将R脚本转换为SAS

时间:2018-10-01 21:03:14

标签: r sas

我想给数据集添加噪音。在R中,这是一个相当简单的过程。我从Laplace分布中采样,然后将该向量加/乘/加到要向其中添加噪声的向量。

问题是,我的同事要求使用SAS中的代码。自从研究生院毕业以来,我就没有使用过SAS,并且我的项目一直处于搁置状态,直到我的同事可以快速使用SAS。

我的代码非常简单:

library ("rmutil")

vector <- c (1,2,3,1,2,3,1,2,3)

vector_prop <- vector/sum(vector)

noise <- rlaplace(9, m=1, s=.1)

new_vector <- vector_prop * noise

我要将我要添加噪声的向量变成一定比例,然后从拉普拉斯分布中绘制。最后,我将这些平局乘以我的比例向量。

由于很难遵循SAS文档,因此任何想法都会有所帮助。我想他们对R文档有同样的感觉。

1 个答案:

答案 0 :(得分:1)

假设您的数据位于名为let flavorLabel: UILabel = { let label = UILabel() label.text = "Pick a Flavor" label.isUserInteractionEnabled = true return label }() let nameTextView: UITextView = { let textView = UITextView() return textView }() let noButton: DLRadioButton = { let button = DLRadioButton(type: .custom) button.setTitle("No", for: .normal) button.setTitleColor(UIColor.lightGray, for: .normal) button.addTarget(self, action: #selector(noButtonPressed), for: .touchUpInside) return button }() let yesButton: DLRadioButton = { let button = DLRadioButton(type: .custom) button.setTitle("Yes", for: .normal) button.setTitleColor(UIColor.lightGray, for: .normal) button.addTarget(self, action: #selector(yesButtonPressed), for: .touchUpInside) return button }() let nextButton: UIButton = { let button = UIButton(type: .system) button.setTitle("Next", for: .normal) button.setTitleColor(UIColor.white, for: .normal) button.isEnabled = false button.backgroundColor = .lightGray button.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) return button }() var choice: Bool? override func viewDidLoad() { super.viewDidLoad() flavorVC.delegate = self } func textViewDidEndEditing(_ textView: UITextView) { handleTextInputChanged() } @objc func handleTextInputChanged() { let isFormValid = nameTextView.text?.count ?? 0 > 0 if isFormValid { nextButton.isEnabled = true nextButton.backgroundColor = .red } else { nextButton.isEnabled = false nextButton.backgroundColor = .lightgray } } @objc fileprivate func noButtonPressed() { choice = false } @objc fileprivate func yesButtonPressed() { choice = true } // delegate method from FlavorController func selectedFlavor(flavor: String) { flavorLabel.text = flavor // eg. "Butter Pecan" } 的数据集中,且变量名为have,则以下代码可能是正确的。由于随机数和流的性质,您不能复制它们,难道每次都不会得到不同的数据集吗?

vector_prop