Permn {DescTools} | R Documentation |
Number and Samples for Permutations or Combinations of a Set
Description
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.
Usage
Permn(x, sort = FALSE)
CombN(n, m, repl = FALSE, ord = FALSE)
CombSet(x, m, repl = FALSE, ord = FALSE, as.list = FALSE)
Arguments
x |
a vector of numeric values or characters. Characters need not be unique. |
n |
number of elements from which to choose. |
m |
number of elements to choose. For |
repl |
logical. Should repetition of the same element be allowed? Defaults to FALSE |
ord |
logical. Does the order matter? Default is FALSE. |
sort |
logical, defining if the result set should be sorted. Default is FALSE. |
as.list |
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. |
Details
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.
Value
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
Author(s)
Friederich Leisch <Friedrich.Leisch@boku.ac.at>
Andri Signorell <andri@signorell.net> (CombSet, CombN)
See Also
combn
, choose
, factorial
, CombPairs
vignette("Combinatorics")
Examples
Permn(letters[2:5])
Permn(2:5)
# 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)