Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

comb_n

All k possible combinations from n elements


Description

All k possible combinations from n elements.

Usage

comb_n(n, k,simplify=TRUE)

Arguments

n

A positive INTEGER number or a vector with numbers.

k

A positive integer number at most equal to n or at most equal to the length of n, if n is a vector.

simplify

A logical value for return List instead of matrix.

Value

A matrix with k columns and rows equal to the number of possible unique combinations of n with k elements. If simplify is set to TRUE then a list with k values where each value has length equal to the number of possible unique combinations of n with k elements.

Author(s)

Manos Papadakis and Marios Dimitriadis

R implementation and documentation: Manos Papadakis <papadakm95@gmail.com> and Marios Dimitriadis <kmdimitriadis@gmail.com>.

References

Nijenhuis A. and Wilf H.S. (1978). Combinatorial Algorithms for Computers and Calculators. Academic Press, NY.

See Also

Examples

system.time( comb_n(20, 4) )
system.time( combn(20, 4) )
x <- rnorm(5)
res<-comb_n(x, 3)

Rfast

A Collection of Efficient and Extremely Fast R Functions

v2.0.1
GPL (>= 2.0)
Authors
Manos Papadakis, Michail Tsagris, Marios Dimitriadis, Stefanos Fafalios, Ioannis Tsamardinos, Matteo Fasiolo, Giorgos Borboudakis, John Burkardt, Changliang Zou, Kleanthi Lakiotaki and Christina Chatzipantsiou.
Initial release
2020-09-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.