permute {jwutil}R Documentation

Generate all permutations of input

Description

Systematically permute the input vector or list, which is very slow for long x. Am amazed something this simple isn't either in base R, or in a straightforward form in a package.

Usage

permute(x)

Arguments

x

list or vector

Details

TODO: limit to a certain cut-off, after which we randomly sample

Value

data frame, each row being one permutation

Examples

ltr <- c("a", "b", "c", "d")
x <- permute(ltr)
print(x)
stopifnot(nrow(x) == factorial(length(ltr)))
ltr <- c("a", "b", "b")
x <- permute(ltr)
print(x)
stopifnot(nrow(x) == factorial(length(ltr)))

[Package jwutil version 1.2.3 Index]