Return 单个 rnorm 函数调用的均值和标准差

Return the mean and standard deviation from a single rnorm function call

  1. 我正在尝试创建一个列表列表,其中包含来自正态分布的均值和标准差值,均值为 5,标准差为 5,样本量为 10,模拟了 50,000 次。

    例如List = ((5, 5), (5, 5), (5, 5))

  2. 我知道我可以执行以下代码从上述过程中生成包含 50,000 个样本均值的向量:

    sample_means_1 <- rep (NA, reps)
    for (i in 1: reps){
        sample_means_1[i] <- mean(rnorm(n_10, 5, 5))
    }
    

    sample_means_1 现在包含 50,000 个样本均值的向量,样本大小为 10

  3. 我不知道如何在使用 rnorm 时从同一个 运行 捕获平均值和标准偏差,并将其插入列表类型结构。

  4. 尝试将 returns 值写入数据帧的方法是否更有意义?

谢谢,

编辑

请注意未来的读者:

  1. 评论中的Ans生成来自@user2974951的列表

    lapply(1:10,function(x){temp=rnorm(10);c(mean(temp),sd(temp))}) 
    
  2. Ans Accepted 从@James

  3. 生成一个矩阵

您可以在 replicate 中使用匿名函数从分布的重复抽取中提取统计数据:

replicate(5, {function(x) c(mean=mean(x),sd=sd(x))}(rnorm(10,5,5)))
         [,1]     [,2]     [,3]     [,4]     [,5]
mean 5.372839 4.042219 4.145441 5.148652 5.202886
sd   3.929017 5.190347 4.802461 5.515714 4.173267