Factorial, Combinations, Permutations

DESCRIPTION:

Compute n!, binomial coefficients, number of combinations and permutations, multinomial coefficients.

USAGE:

factorial(n) 
lfactorial(n) 
choose(n, k, order.matters=F) 
choose.multinomial(n, m) 

REQUIRED ARGUMENTS:

n
integer vector. Must be length 1 for choose.multinomial. Need not be integer for factorial or lfactorial.
k
integer vector.
m
integer vector, which sums to n.

VALUE:

a numeric vector:

factorial(n) is n!

lfactorial(n) is the natural logarithm of n!

choose(n, k) is n! / ( k! (n-k)!), i.e. the binomial coefficients.

choose(n, k, order.matters=T) is n! / (n-k)!, i.e. the number of ordered subsets of length k from a set with n distinct elements.

choose.multinomial(n, m) is n!/ prod(m! ), the multinomial coefficients.

DETAILS:

These functions use gamma and lgamma for computations.

SEE ALSO:

, , .

EXAMPLES:

factorial(5) 
choose(5, 2) 
choose(5, -1:6) 
choose.multinomial(6, c(3,1,2)) 
choose(5, 2, order=T)