nat_to_sub {simplextree} | R Documentation |
nat_to_sub
Description
Computes the x
^th (n
choose 2
) combination.
Usage
nat_to_sub(x, n, k)
Arguments
x |
non-negative integers in the range |
n |
numerator of the binomial coefficient |
k |
denominator of the binomial coefficient |
Details
The mapping is done via an lexicographically-ordered combinadic mapping.
In general, this function is not intended to be used to generate all (n choose k
) combinations in the combinadic mapping.
Value
integer matrix whose columns give the combinadics of x
.
References
McCaffrey, J. D. "Generating the mth lexicographical element of a mathematical combination." MSDN Library (2004).
Examples
library(simplextree)
all(nat_to_sub(seq(choose(100,2)), n = 100, k = 2) == combn(100,2))
## Generating pairwise combinadics is particularly fast
## Below: test to generate ~ 45k combinadics (note: better to use microbenchmark)
system.time({
x <- seq(choose(300,2))
nat_to_sub(x, n = 300, k = 2L)
})
## Compare with generating raw combinations
system.time(combn(300,2))
[Package simplextree version 1.0.1 Index]