\name{combination}
\alias{combination}
\alias{ncombination}
\title{ Combinations }
\description{
  Calculating and creating combinations
}
\usage{
ncombination(k, n, replace = FALSE)
combination(k, n=NULL, x=NULL, replace = FALSE)
}
\arguments{
  \item{k}{ number of positions }
  \item{n}{ poolsize }
  \item{x}{ vector pool of values, can be given instead of n }
  \item{replace}{ default FALSE, TRUE to allow reusing of pool elements }
}
\details{
  \code{ncombination} returns the number of combinations, \code{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{ Jens Oehlschlägel }
\seealso{ \code{\link{permutation}}, \code{\link{labelation}}, \code{\link[base]{choose}}, \code{\link[gregmisc]{permutations}} }
\examples{
  ncombination(2,4)
  combination(2,4)
  combination(2,x=letters[1:4])
  ncombination(2,4,replace=TRUE)
  combination(2,4,replace=TRUE)

  \dontrun{
  ## 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))
  }
}
\keyword{ iteration }
