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)
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 rand
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)))
Please correct me if I am wrong. Thanks
--
View this message in context:
http://n4.nabble.com/How-to-use-ifelse-to-generate-random-value-from-a-distribution-tp1597064p1597102.html
Se
I need use different parameters of distribution for different case to
generate random value, but I use ifelse, the generated value is fixed
without change.
Here is example
data1
y x
1 1 2
2 2 1
3 3 2
4 4 3
5 5 3
6 6 1
7 7 2
8 8 1
9 9 1
10 10 3
11 11 3
12 12 2
ifelse(data1$x
4 matches
Mail list logo