一、總結
組合數:choose(n,k) —— 從n個中選出k個
階乘:factorial(k) —— k!
排列數:choose(n,k) * factorial(k)
冪:^
余數:%%
整數商:%/%
列出所有組合數矩陣:combn(x,n)
t(combn(x,n)) 轉置
二、具體例子
choose(5,3) # 10 factorial(5) # 120 choose(5,3)*factorial(3) # 60
2^10 # 1024
10 %% 3 # 1
10 %/% 3 # 3
x <- 1:5 n <-3 combn(x,n) /* [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 1 1 1 1 1 2 2 2 3 [2,] 2 2 2 3 3 4 3 3 4 4 [3,] 3 4 5 4 5 5 4 5 5 5 */
t(combn(x,n)) /* [,1] [,2] [,3] [1,] 1 2 3 [2,] 1 2 4 [3,] 1 2 5 [4,] 1 3 4 [5,] 1 3 5 [6,] 1 4 5 [7,] 2 3 4 [8,] 2 3 5 [9,] 2 4 5 [10,] 3 4 5 */
END 2018-11-26 11:07:27