Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nchoosek

Binomial Coefficients


Description

Compute the Binomial coefficients.

Usage

nchoosek(n, k)

Arguments

n, k

integers with k between 0 and n

Details

Alias for the corresponding R function choose.

Value

integer, the Binomial coefficient ({n \over k}).

Note

In Matlab/Octave, if n is a vector all combinations of k elements from vector n will be generated. Here, use the function combs instead.

See Also

Examples

S <- sapply(0:6, function(k) nchoosek(6, k))  # 1  6 15 20 15  6  1

# Catalan numbers
catalan <- function(n) choose(2*n, n)/(n+1)
catalan(0:10)
# 1  1  2  5  14  42  132  429  1430  4862  16796

# Relations
n <- 10
sum((-1)^c(0:n) * sapply(0:n, function(k) nchoosek(n, k)))  # 0

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.