Learn R Programming

gRbase (version 1.8-5.1)

combn_prim: Generate All Combinations of n Elements Taken m at a Time

Description

Generate all combinations of the elements of x taken m at a time. If x is a positive integer, returns all combinations of the elements of seq(x) taken m at a time.

Usage

combn_prim(x, m, simplify = TRUE)

Arguments

x

vector source for combinations, or integer n for x <- seq(n).

m

number of elements to choose.

simplify

logical indicating if the result should be simplified to a matrix; if FALSE, the function returns a list.

Value

A matrix or a list.

See Also

combn

Examples

Run this code
# NOT RUN {
x <- letters[1:5]
m <- 3

combn(x, m)
combn_prim(x, m)

combn(m, m)
combn_prim(m, m)

combn(x, m, simplify=FALSE)
combn_prim(x, m, simplify=FALSE)

x <- letters[1:20]

# }
# NOT RUN {
system.time({ for (i in 1:100) { combn_prim(x,m) }})
system.time({ for (i in 1:100) { combn(x,m) }})

system.time({ for (i in 1:100) { combn_prim(x,m, simplify=FALSE) }})
system.time({ for (i in 1:100) { combn(x,m, simplify=FALSE) }})
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab