perm {lazy.tools} | R Documentation |
Generate all m-permutations of n without repetition
perm(n, m, vals = 1:n, noreverse = 0)
n |
total # of elements |
m |
# of elements to choose |
vals |
a vector of values to be permuted |
noreverse |
= 1 to remove reverse-equivalent rows |
The recursive algorithm below is used.
res=NULL for( i in 1:n ){ res <- rbind(res, cbind(vals[i], Recall(n - 1, m - 1, vals[-i]))) }
The method of removal of reverse-equivalent rows comes from
the answer to stack overflow question:
"How to remove reverse rows in a permutation matrix?"
by obchardon at Sep 15, 2020 at 7:46
https://stackoverflow.com/questions/63896177/how-to-remove-reverse-rows
-in-a-permutation-matrix
A matrix of the size P(n,m) x m.
n <- 5
for( m in 1:n )
Print( m, perm(n,m), comb(n,m) )
Print( perm(3,3), perm(3,3,,1) )