permutations: Generate all or some permutations of a vector

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

View source: R/permutations.R

Description

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.

Usage

1
permutations(x, idx=NULL, method="lexicographic")

Arguments

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".

Value

Returns a matrix with N columns and length(idx) (or 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 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.

Examples

 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!")

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