Learn R Programming

CombMSC (version 1.4.2.1)

subsets: Generate all the combinations of k out of n elements

Description

Generates all different subsets of size \(r\) chosen from \(n\) different elements.

Usage

subsets(n, r, v = 1:n)

Arguments

n

Numeric. Number of elements to choose from.

r

Numeric. Size of the desired subsets.

v

Vector. Numeric or character vector of size n with the labels of the \(n\) elements to choose from.

Value

A matrix of dimension (\(N \times r\)), where \(N\) is the total number of different combinations of \(r\) elements chosen from \(n\) possible.

References

Venables, Bill. "Programmers Note", R-News, Vol 1/1, Jan. 2001. http://cran.r-project.org/doc/Rnews

See Also

combinations of the gtools package.

Examples

Run this code
# NOT RUN {
subsets(5,3)
subsets(5,3,letters)
subsets(5,3,c(10,20,30,50,80))
# }

Run the code above in your browser using DataLab