# combs: All Combinations of k Elements from Vector v In caTools: Tools: Moving Window Statistics, GIF, Base64, ROC AUC, etc

## Description

Finds all unordered combinations of `k` elements from vector `v`.

## Usage

 `1` ```combs(v,k) ```

## Arguments

 `v` Any numeric vector `k` Number of elements to choose from vector `v`. Integer smaller or equal than length of `v`.

## Value

`combs(v,k)` (where `v` has length `n`) creates a matrix with n!/((n-k)! k!) (`n` choose `k`) rows and `k` columns containing all possible combinations of `n` elements taken `k` at a time.

## Author(s)

Jarek Tuszynski (SAIC) jaroslaw.w.tuszynski@saic.com

I discovered recently that R packages already have two functions with similar capabilities: `combinations` from gTools package and Also similar to Matlab's `nchoosek` function (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/nchoosek.html)

## Examples

 ```1 2 3 4 5 6``` ``` combs(2:5, 3) # display examples combs(c("cats", "dogs", "mice"), 2) a = combs(1:4, 2) b = matrix( c(1,1,1,2,2,3,2,3,4,3,4,4), 6, 2) stopifnot(a==b) ```

### Example output

```     [,1] [,2] [,3]
[1,]    2    3    4
[2,]    2    3    5
[3,]    2    4    5
[4,]    3    4    5
[,1]   [,2]
[1,] "cats" "dogs"
[2,] "cats" "mice"
[3,] "dogs" "mice"
```

caTools documentation built on March 28, 2021, 9:07 a.m.