alex46015 wrote:
I think I figure it out.

ifelse(data1$x==1,rnorm(12,2,1),ifelse(data1$x==2,rnorm(12,-2,1),rnorm(12,110,1)))


Where is the number 12 coming from? Is that the length of data1$x?


Here is a sample using the fact that rnorm can accept vectors of means and sds. My x is randomly generated since you did not provide a reproducible example.

#random data, can take on 3 values

x <- sample(1:3, 100, replace = TRUE)

#i tried to make this identical to your criteria

mns <- ifelse(x == 1, 2, ifelse(x==2, -2, 110))

#use vectors!, do not hardcode length(x)!

rnorm(length(x), mns)


HTH,
--Erik

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to