comb {lazy.tools}R Documentation

Generate all combinations of n elements taken m at a time.

Description

This is very slow when n is large.

Usage

comb(n, m)

Arguments

n

total # of elements

m

# of elements to choose

Details

This function uses cprod function to calculate combinations.
For example, n choose 3 will be calculated as:
x <- 1:n
y <- cprod(x,x[-1])
y <- y[y[,1]<y[,2],]
y <- cprod(y,x[-(1:2)])
y <- y[y[,2]<y[,3],]

Value

A matrix of the size choose(n,m) x m.

Examples

n <- 5
for( m in 1:n )
 Print( m,choose(n,m), comb(n,m) )


[Package lazy.tools version 0.1.3 Index]