comb {lazy.tools} | R Documentation |
This is very slow when n is large.
comb(n, m)
n |
total # of elements |
m |
# of elements to choose |
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],]
A matrix of the size choose(n,m) x m.
n <- 5
for( m in 1:n )
Print( m,choose(n,m), comb(n,m) )