choose(k, n) calculates the number of sets with n elements than can be chosen from a set with k elements, that is the binomial coefficient n <- 3 k <- 7 choose(k, n) # # 35
choose() can be calculated with the formula for the binomial coefficient n <- 3
k <- 7
a <- 1
b <- 1
for (i in 1:n) {
a <- a * i
b <- b * (k-i+1)
}
paste0('choose(', k, ',', n, '), alternatively calculated: ', b/a)
#
# choose(7,3), alternatively calculated: 35