The choose()
function in R is used to calculate the number of sets with n
elements that can be chosen from a set with k
elements.
Mathematically:
choose (k, n) =
Note:
n
must always be greater thank
.
choose(k, n)
The choose()
function takes the following parameter values:
n
: This represents the number of elements of a given set.k
: This represents the number of elements of another set.Let’s look at the code below:
# creating the number elementsn <- 3# number of elements of a particular setk <- 5# use of choose() function to find how many times a set with 5 elements can be choosen from a set with 3 elements.print(choose(k, n))
Line 1: We obtain the number of elements.
Line 5: We obtain the number of elements of a particular set.
Line 8: We call the built-in function choose()
with the parameters k
and n
.
Mathematically:
choose (n, k) =
choose (5, 3) = = = 10
Therefore, only 10
sets can be formed of a set with 5
elements chosen from another set having 3
elements.