permuteWithRepeats: Generate all permutations of input, reusing values in each...

Description Usage Arguments Value Examples

View source: R/util.r

Description

Expand the given vector into all possible values in each location, with or without duplicates.

Usage

1

Arguments

x

list or vector

unique

logical, if TRUE, the default, only unique results are returned

Value

data frame, each row being one permutation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
ltr <- c("a", "b", "c")
x <- permuteWithRepeats(ltr, unique = FALSE)
print(x)
stopifnot(nrow(x) == length(ltr)^length(ltr))
# duplicate results are dropped
y <- permuteWithRepeats(c("X", "Y", "Y"))
print(y)
stopifnot(nrow(y) == 2^3)
z <- permuteWithRepeats(c("X", "Y", "Y", "Y"))
stopifnot(nrow(z) == 2^4)
a <- permuteWithRepeats(c(1, 2, 3, 1))
stopifnot(nrow(a) == 3^4)

jwutil documentation built on May 7, 2019, 1:03 a.m.