Permn {DescTools}R Documentation

Number and Samples for Permutations or Combinations of a Set


Return the set of permutations for a given set of values. The values can be numeric values, characters or factors. CombN computes the number of combinations with and without replacement and order, whereas CombSet returns the value sets.


Permn(x, sort = FALSE)

CombN(n, m, repl = FALSE, ord = FALSE)
CombSet(x, m, repl = FALSE, ord = FALSE, as.list = FALSE)



a vector of numeric values or characters. Characters need not be unique.


number of elements from which to choose.


number of elements to choose. For CombSet can m be a numeric vector too.


logical. Should repetition of the same element be allowed? Defaults to FALSE


logical. Does the order matter? Default is FALSE.


logical, defining if the result set should be sorted. Default is FALSE.


logical, defining if the results should be returned in a flat list, say every sample is a single element of the resulting list. Default is FALSE.


The vector x need not contain unique values. The permutations will automatically be filtered for unique sets, if the same element is given twice or more.


a matrix with all possible permutations or combinations of the values in x for Permn and CombSet
if m contains more than one element the result will be a list of matrices or a flat list if as.list is set to TRUE
an integer value for CombN


Friederich Leisch <>
Andri Signorell <> (CombSet, CombN)

See Also

combn, choose, factorial, CombPairs



# containing the same element more than once
Permn(c("a", "b", "c", "a"))

# only combinations of 2, but in every possible order
x <- letters[1:4]
n <- length(x)
m <- 2

# the samples
CombSet(x, m, repl=TRUE, ord=FALSE)
CombSet(x, m, repl=TRUE, ord=TRUE)
CombSet(x, m, repl=FALSE, ord=TRUE)
CombSet(x, m, repl=FALSE, ord=FALSE)

# the number of the samples
CombN(n, m, repl=TRUE, ord=FALSE)
CombN(n, m, repl=TRUE, ord=TRUE)
CombN(n, m, repl=FALSE, ord=TRUE)
CombN(n, m, repl=FALSE, ord=FALSE)

# build all subsets of length 1, 3 and 5 and return a flat list
x <- letters[1:5]
CombSet(x=x, m=c(1, 3, 5), as.list=TRUE)

[Package DescTools version 0.99.51 Index]