'Limit the amount of data from rnorm with over a certain number
I want that only 20 datasets will be bigger or equal to 60 and the other 20 will be under 60. Can anyone help me?
X_old_q <- rnorm(40, mean = 64.03125, sd = 10)
Solution 1:[1]
This is the first idea I came up with. I am sure there is a much, much better approach to your problem, but this one fixes your issue:
lowerSample = c()
while(length(lowerSample) < 20) {
value = rnorm(1, mean = 64.03125, sd = 10)
if(value < 60) {
lowerSample = c(lowerSample, value)
}
}
upperSample = c()
while(length(upperSample) < 20) {
value = rnorm(1, mean = 64.03125, sd = 10)
if(value >= 60) {
upperSample = c(upperSample, value)
}
}
X_old_q = c(lowerSample, upperSample)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zingzang |
