| permutations {R.basic} | R Documentation |
Generate all or some permutations of a vector according to a specified permutation scheme by calling an underlying permutation generator. Currently only lexicographical permutations can be generated.
lexicographicPermutations(x, idx=NULL, method="lexicographic")
x |
The vector from which the permutations should be generated. |
idx |
A vector of integers specifying which permutations in order
to be generated. If NULL, all permutations are generated. |
method |
Specifies the permutation scheme to be used. Valid
values are "lexicographic". |
Returns a matrix with N columns and length(idx)
(or N!) rows, where N is the length of the vector.
Henrik Bengtsson, http://www.braju.com/R/
See lexicographicPermutations() to generate all
lexicographic permutations of a vector and
lexicographicPermutation() to generate (only) the n:th
lexicographic permutation of a vector.
See x[sample(n)] to generate a random permutation.
x <- c("a", "b", "c", "d")
p1 <- permutations(x)
print(p1)
p2 <- lexicographicPermutations(x)
print(p2)
if (!identical(p1, p2))
stop("Permutations 'p1' and 'p2' should be identical!")