Learn R Programming

evanverse (version 0.3.7)

comb: comb: Calculate Number of Combinations C(n, k)

Description

Calculates the total number of ways to choose k items from n distinct items (without regard to order), i.e., the number of combinations C(n, k) = n! / (k! * (n - k)!). This function is intended for moderate n and k. For very large values, consider the 'gmp' package.

Usage

comb(n, k)

Value

Numeric. The combination count C(n, k) (returns Inf for very large n).

Arguments

n

Integer. Total number of items (non-negative integer).

k

Integer. Number of items to choose (non-negative integer, must be \u2264 n).

Examples

Run this code
comb(8, 4)      # 70
comb(5, 2)      # 10
comb(10, 0)     # 1
comb(5, 6)      # 0

Run the code above in your browser using DataLab