lexicographicPermutations: Generate all lexicographic permutations of a vector

Description Usage Arguments Value Author(s) References See Also Examples

Description

Generate all lexicographic permutations of a vector. If the vector is of length N, there are N! permutation.

Usage

1
2
## Default S3 method:
lexicographicPermutations(x, ...)

Arguments

x

The vector from which all permutations should be generated.

...

Not used.

Value

Returns a matrix with N columns and N! rows, where N is the length of the vector.

Author(s)

Henrik Bengtsson

References

[1] A.G. Thakurta, Lexicographic Permutation Analysis, http://www.cs.wpi.edu/~dobrush/cs504/f02/projects/Anupama.htm

See Also

See lexicographicPermutation() to generate (only) the n:th lexicographic permutation of a vector. See permutations() for a wrapper function to generate different types of permutations. See x[sample(n)] to generate a random permutation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
x <- c("a", "b", "c", "d")

p1 <- NULL
for (k in 1:factorial(length(x))-1)
  p1 <- rbind(p1, lexicographicPermutation(x, k))
print(p1)

p2 <- lexicographicPermutations(x)
print(p2)

if (!identical(p1, p2))
  stop("Permutations 'p1' and 'p2' should be identical!")

HenrikBengtsson/R.basic documentation built on May 6, 2019, 11:51 p.m.