Description Usage Arguments Value Note Author(s) See Also Examples
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.
1 | combn_prim(x, m, simplify = TRUE)
|
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. |
A matrix or a list.
The combn_prim function is a simplified version of the combn function. However, combn_prim is implemented in C and is considerably faster than combn.
P. T. Wallace and Søren Højsgaard
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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) }})
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.