Description Usage Arguments Value Author(s) References See Also Examples
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.
1 | permutations(x, idx=NULL, method="lexicographic")
|
x |
The |
idx |
A |
method |
Specifies the permutation scheme to be used. Valid
values are |
Returns a matrix
with N columns and length(idx)
(or N!) rows, where N is the length of the vector.
Henrik Bengtsson
[1] A.G. Thakurta, Lexicographic Permutation Analysis,
http://www.cs.wpi.edu/~dobrush/cs504/f02/projects/Anupama.htm
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.
1 2 3 4 5 6 7 8 9 10 | 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!")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.