Use of IF function in R

Viewed 61222

I am running a short if function in R but am getting the following warning message:

In if ((runif(50, 0, 1) < 0.69)) { :  the condition has length > 1 and only the first element will be used`. 

My rudimentary grasp of R leads me to believe that runif generates a vector but if yields a single value, so I'm thinking this is the issue. Is there any simple substitution for if here?

Also i want the end product to be a matrix combination of the two arguments but i wasn't sure if it was correct to put 50 in the rnorm function for both scenarios.

Test <-
 if((runif(50, 0, 1)<0.69)) {
 rnorm(50, 25, 4)
 } else {
 rnorm(50, 28, 4.3)
}
2 Answers
Related