nCr: Calculate the number of possible combinations of n objects,...

View source: R/stat_funcs.R

nCrR Documentation

Calculate the number of possible combinations of n objects, taken r at a time without repitition

Description

Calculates the number of arrangements in which no element occurs more than once and order does not matter, without the requirement of using all the elements from a given set. For example, if we were arranging an apple, a pear, and an orange (n = 3) into sets of two (k = 2), we would find that there are three possible combinations: an apple and a pear, an apple and an orange, and a pear and an orange. We would not count combinations where the order was reversed (e.g. a pear and an apple) as different combinations.

Usage

nCr(n, r)

Arguments

n

An integer number of elements to choose from for the combination. May be a vector if r has a single element (i.e. length(r) == 1).

r

An integer subgroup size to combine. May be a vector if n has a single element (i.e. length(n) == 1).

Details

Implements the equation

n! / (r! * (n - r)!)

Value

An integer number of possible permutations

Examples

  ## Not run: 
    nCr(3, 2)
    nCr(3:5, 2)
    nCr(5, 2:4)
    nCr(1:5, 3)
  
## End(Not run)

tomhopper/numbr documentation built on Nov. 5, 2022, 11:35 p.m.