permutations {R.basic}R Documentation

Generate all or some permutations of a vector

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

  lexicographicPermutations(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, http://www.braju.com/R/

References

  • 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

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

    [Package Contents]