dimanche 3 juin 2018

Random number generator for the vector in R

I have a question when I try to replicate the results, I come up with a problem.

l <- {}
for(i in 1:3){
  set.seed(1)
  l[i] <- rnorm(n = 1, i, i)  
}

this will produce

0.3735462 0.7470924 1.1206386

However, if I write

set.seed(1)
rnorm(n = 3, 1:3, 1:3)
0.3735462 2.3672866 0.4931142

Or

set.seed(1)
rmvnorm(n = 1, 1:3, sqrt(diag(1:3)))
0.3735462 2.21839 1.900251

I don't get the same result. What can a be a problem? My goal is vectorize the for loop, that's why I come up with a problem.




Aucun commentaire:

Enregistrer un commentaire