permuteWithRepeats {jwutil} | R Documentation |
Expand the given vector into all possible values in each location, with or without duplicates.
permuteWithRepeats(x, unique = TRUE)
x |
list or vector |
unique |
logical, if |
data frame, each row being one permutation
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)