标签: r statistics probability-distribution
我有一个程序可以模拟骰子掷骰100次。我需要知道如何运行该程序10 ^ 5次,我认为这与数字有关。
set.seed(123) x <- sample(1:6, size=100, replace = TRUE) hist(x, main="10^6 fair rolls", xlab = "Dice Result", ylab = "Probability", xlim=c(0.5,6.5), breaks=-1:100+.5, prob=TRUE )
答案 0 :(得分:0)
根据@markus的建议,您可以使用replicate:
replicate
set.seed(123) nTime <- 10^5 x <- replicate(nTime, sample(1:6, size=100, replace = TRUE)) hist(x, main="10^6 fair rolls", xlab = "Dice Result", ylab = "Probability", xlim=c(0.5,6.5), breaks=-1:100+.5, prob=TRUE )