22 Permutation and combination
As a matter of fact, a permutation is an ordered combination. There are basically two types of permutations, with repetition (or replacement) and without repetition (without replacement).
require(combinat)
## Loading required package: combinat
##
## Attaching package: 'combinat'
## The following object is masked from 'package:utils':
##
## combn
permn(3)
## [[1]]
## [1] 1 2 3
##
## [[2]]
## [1] 1 3 2
##
## [[3]]
## [1] 3 1 2
##
## [[4]]
## [1] 3 2 1
##
## [[5]]
## [1] 2 3 1
##
## [[6]]
## [1] 2 1 3
combn(3, 2)
## [,1] [,2] [,3]
## [1,] 1 1 2
## [2,] 2 3 3
length(permn(3))
## [1] 6
dim(combn(3,2))[2]
## [1] 3
22.1 Reference
Combinations and Permutations: https://www.mathsisfun.com/combinatorics/combinations-permutations.html
Combinations and permutations in R: https://davetang.org/muse/2013/09/09/combinations-and-permutations-in-r/