Skip to content
Related Articles
Calculate nCr value in R Programming – choose() Function
• Last Updated : 01 Jun, 2020

R Language offers a direct function that can compute the nCr value without writing the whole code for computing nCr value.

Syntax: choose(n, r)

Parameters:
n: Number of elements
r: Number of combinations

Returns: The number of r combinations from a total of n elements, i.e, nCr value.

Example 1:

 `# R program to calculate nCr value ``   ` `# Using choose() method ``answer1 <``-` `choose(``3``, ``2``) ``answer2 <``-` `choose(``3``, ``7``)  ``answer3 <``-` `choose(``7``, ``3``)`` ` `print``(answer1) ``print``(answer2) ``print``(answer3) `

Output:

```3
0
35
```

Example 2: If we provide the value of n and r such that n < r then choose(n, r) will return 0.

 `# R program to calculate nCr value ``    ` `# Using choose() method ``answer1 <``-` `choose(``2``, ``3``) ``answer2 <``-` `choose(``3``, ``6``)  ``answer3 <``-` `choose(``3``, ``7``)``  ` `print``(answer1) ``print``(answer2) ``print``(answer3) `

Output:

```0
0
0
```
My Personal Notes arrow_drop_up