combination {truecluster} | R Documentation |
Calculating and creating combinations
ncombination(k, n, replace = FALSE) combination(k, n=NULL, x=NULL, replace = FALSE)
k |
number of positions |
n |
poolsize |
x |
vector pool of values, can be given instead of n |
replace |
default FALSE, TRUE to allow reusing of pool elements |
ncombination
returns the number of combinations, combination
returns a matrix of combinations. No special sequence granted. Implemented in C, but not faster than the functions in gregmisc.
A matrix of (k x ncombination)
Jens Oehlschlägel
permutation
, labelation
, choose
, permutations
ncombination(2,4) combination(2,4) combination(2,x=letters[1:4]) ncombination(2,4,replace=TRUE) combination(2,4,replace=TRUE) ## Not run: ## regression test require(gregmisc) k <- 4 n <- 6 replace <- FALSE a <- sort(apply(combination(k,n,replace=replace), 2, paste, collapse="-")) b <- sort(apply(combinations(n,k,rep=replace), 1, paste, collapse="-")) stopifnot(length(a)==ncombination(k,n,replace=replace)) stopifnot(identical(a,b)) replace <- TRUE a <- sort(apply(combination(k,n,replace=replace), 2, paste, collapse="-")) b <- sort(apply(combinations(n,k,rep=replace), 1, paste, collapse="-")) stopifnot(length(a)==ncombination(k,n,replace=replace)) stopifnot(identical(a,b)) ## End(Not run)