rnorm()
是一個量化的功能。因此matrix(rnorm(500 * 20, 0, 4), nrow = 500))
或類似應該工作。
set.seed(1237)
head(matrix(rnorm(500 * 20, 0, 4), nrow = 500), 2)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] -1.779413 2.0934980 -0.1130465 0.7155059 -4.357417 -0.1000385 -5.4510753 -2.135156 0.2134115 -6.747588 2.3818280
[2,] -7.892865 -0.6712141 -4.0481822 5.2750330 -3.053245 0.7502157 0.6026951 4.951890 1.8733383 1.860631 -0.7452204
[,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20]
[1,] 4.0730359 -3.246457 5.781667 2.4091225 -8.4262348 7.1438989 3.289772 -4.136308 -0.7102701
[2,] -0.5159794 4.144834 5.662559 0.9685914 0.9033701 0.3952698 10.734498 -2.213788 -2.3064852
我不確定我是否相信。你使用'set.seed()'? '矩陣(rnorm(20 * 500,0,4),ncol = 20)'怎麼樣? –
運行'for(i in 1:2){print(rnorm(n = 20,mean = 0,sd = 4))}'真的會爲您打印兩次相同的向量嗎?它當然不適合我。 – josliber
你每次都給e賦值,如何使e [i] <-rnorm(n = 20,mean = 0,sd = 4)?並在循環之前聲明e <-as.list() – infominer