** combn()** function in R Language is used to generate all combinations of the elements of

*taken*

**x****at a time.**

*m*

Syntax:combn(x, m)

Parameters:

x:total number of elements taken

r:number of elements taken at a time out of “x” elements

**Example 1:**

`# R program to illustrate ` `# combn function ` ` ` `# Calling the combn() function ` `combn(` `5` `, ` `3` `) ` `combn(` `6` `, ` `5` `) ` `combn(` `2` `, ` `2` `) ` |

*chevron_right*

*filter_none*

**Output:**

[, 1] [, 2] [, 3] [, 4] [, 5] [, 6] [, 7] [, 8] [, 9] [, 10] [1, ] 1 1 1 1 1 1 2 2 2 3 [2, ] 2 2 2 3 3 4 3 3 4 4 [3, ] 3 4 5 4 5 5 4 5 5 5 [, 1] [, 2] [, 3] [, 4] [, 5] [, 6] [1, ] 1 1 1 1 1 2 [2, ] 2 2 2 2 3 3 [3, ] 3 3 3 4 4 4 [4, ] 4 4 5 5 5 5 [5, ] 5 6 6 6 6 6 [, 1] [1, ] 1 [2, ] 2

**Example 2:**

`# R program to illustrate ` `# combn function ` ` ` `# Calling the combn() function ` `combn(LETTERS[` `1` `: ` `4` `], ` `2` `) ` `combn(LETTERS[` `2` `: ` `6` `], ` `3` `) ` |

*chevron_right*

*filter_none*

**Output:**

[, 1] [, 2] [, 3] [, 4] [, 5] [, 6] [1, ] "A" "A" "A" "B" "B" "C" [2, ] "B" "C" "D" "C" "D" "D" [, 1] [, 2] [, 3] [, 4] [, 5] [, 6] [, 7] [, 8] [, 9] [, 10] [1, ] "B" "B" "B" "B" "B" "B" "C" "C" "C" "D" [2, ] "C" "C" "C" "D" "D" "E" "D" "D" "E" "E" [3, ] "D" "E" "F" "E" "F" "F" "E" "F" "F" "F"

## Recommended Posts:

- Create a Data Frame of all the Combinations of Vectors passed as Argument in R Programming - expand.grid() Function
- Generate Factors with specified Levels in R Programming - gl() Function
- Generate Color Vectors of desired Length in R Programming - rainbow() Function
- Generate a Sequence from 1 to any Specified Number in R Programming - seq_len() Function
- Generate a Sequence of Length of the passed Argument in R Programming - seq_along() Function
- Generate Data sets of same Random Values in R Programming - set.seed() Function
- Generate a set of Sample data from a Data set in R Programming - sample() Function
- Generate a Vector of specified length with each element as a unique color on RGB scale in R Language - topo.colors() Function
- Generate a Vector of specified length with each element as a unique color on RB scale in RGB spectrum in R Language - cm.colors() Function
- Generate a Vector of specified length with each element as a unique color on RG scale in RGB spectrum in R Language - terrain.colors() Function
- Check if a Function is a Primitive Function in R Programming - is.primitive() Function
- Check if values in a vector are True or not in R Programming - all() and any() Function
- Replace all the matches of a Pattern from a String in R Programming - gsub() Function
- Get a List of all the Attached Packages in R Programming - search() Function
- Get the Full Path of all the Attached Packages in R Programming - searchpath() Function
- List all the Objects present in the Current Working Directory in R Programming - ls() Function
- Get a List of all the 657 colors in R Programming - colors() Function
- Compute Density of the Distribution Function in R Programming - dunif() Function
- Apply a Function over a List of elements in R Programming - lapply() Function
- Search the Interval for Minimum and Maximum of the Function in R Programming - optimize() Function

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.