The function
permutations(n)
from package e1071, returns a matrix containing all permutations of the integers 1:n (one permutation per row). For example:
> permutations(3)
      [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    1    3
[3,]    2    3    1
[4,]    1    3    2
[5,]    3    1    2
[6,]    3    2    1
A weaker meaning of the term permutation indicates those ordered arrangements in which no element occurs more than once, but without the requirement of using all the elements from a given set. I'm considering, in particular, the arrangements of a fixed length k of elements taken from a given set of size n, in other words: k-permutations of n.
How can I obtain a matrix containing all k-permutations of the integers 1:n (one permutation per row)?