Create a function which returns mean and sd for one iteration.
return_mean_sd <- function() {
dist = sample(c(0:200), 10, replace = TRUE)
c(mean = mean(dist), sd = sd(dist))
}
You can call this function n
times to create a dataframe.
set.seed(123)
sim_df <- as.data.frame(t(replicate(100, return_mean_sd())))
head(sim_df)
# mean sd
#1 105.0 70.3
#2 119.7 44.3
#3 91.6 56.1
#4 91.5 58.7
#5 99.1 55.2
#6 90.0 52.1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…