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