R 中的概率谜题
Peter Chi
Assistant Professor of Statistics
第1章:经典问题
第2章:骰子游戏
第3章:源自网络
第4章:扑克游戏
factorial(n)factorial(3) $= 3! = 3 \times 2 \times 1$factorial(3)
6
choose(n,k)choose(5,3) $ = {5 \choose 3} = \frac{5!}{3! \times (5-3)!} $choose(5,3)
10
sample()rbinom()replicate()for、whileset.seed()for(i in 1:10){
sum(sample(x = c(1,2,3,4,5,6), size = 2, replace = TRUE))
}
存储结果:
rolls <- rep(NA, 10) for(i in 1:10){ rolls[i] <- sum(sample(x = c(1,2,3,4,5,6), size = 2, replace = TRUE)) }rolls
3 6 3 9 9 3 6 11 9 10
my_function <- function(n){
answer <- n^3
return(answer)
}
my_function(10)
1000
R 中的概率谜题