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

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/combnPrimR.R

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

1
combnPrim(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.

Note

The combnPrim function is a simplified version of the combn function. However, combnPrim is implemented in C and is considerably faster than combn.

Author(s)

P.T.Wallace and S<f8>ren H<f8>jsgaard

See Also

combn

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
x <- letters[1:20]
m <- 3

combn(x,m)
combnPrim(x,m)

combn(m,m)
combnPrim(m,m)

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

system.time({ for (ii in 1:100) { combnPrim(x,m) }})
system.time({ for (ii in 1:100) { combn(x,m) }})

system.time({ for (ii in 1:100) { combnPrim(x,m, simplify=FALSE) }})
system.time({ for (ii in 1:100) { combn(x,m, simplify=FALSE) }})

gRbase documentation built on May 2, 2019, 4:51 p.m.