Thanks for all you guys' help above.  Actually my question is for Multivariate Normal  m1<-c(2.5,3.5,4.5) m2<-c(-3,-4,-5) m3<-c(100,120,130) n1<-length(data$x) sigma1<-matrix(c(1,0.3,0.4,0.3,1,0.2,0.4,0.2,1),nrow=3,byrow=T)  trait1<-ifelse(data$x==1,list(rmvnorm(n1,mean=m11,sigma=sigma1)),ifelse(data$x==2,list(rmvnorm(n1,mean=m12,sigma=sigma1)),list(rmvnor m(n1,mean=m13,sigma=sigma1))))  I don't know why the way wroks for rnorm, but it doesn't work for rmvnorm. Do you know a way to fix it?
-- View this message in context: http://n4.nabble.com/How-to-use-ifelse-to-generate-random-value-from-a-distribution-tp1597064p1597400.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
______________________________________________ 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.