combination {truecluster}R Documentation

Combinations

Description

Calculating and creating combinations

Usage

ncombination(k, n, replace = FALSE)
combination(k, n=NULL, x=NULL, replace = FALSE)

Arguments

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

Details

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.

Value

A matrix of (k x ncombination)

Author(s)

Jens Oehlschlägel

See Also

permutation, labelation, choose, permutations

Examples

  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)

[Package truecluster version 0.3 Index]