Reputation: 31
I made a program that stores negative values from deviates of a normal distribution using ifelse():
n <- 100000
z <- rnorm(n)
ifelse(z<0,z,___)
However, I want the function to work so that if the deviate is positive, the function would skip that value and proceed to the next one (I don't want to put "NA" in the no argument of the ifelse function). Is there any argument I can put in the ___ to get what I need? Thank you!
Upvotes: 0
Views: 691
Reputation: 78927
An option could be:
n <- 100000
z <- rnorm(n)
if(z < 0) {
print(z)
}
Upvotes: 1
Reputation: 521103
If sounds to me like you really want to subset the vector:
n <- 100000
z <- rnorm(n)
z <- z[z < 0]
Upvotes: 1