Description Usage Arguments Details Value References Examples
Computes the x
^th (n
choose 2
) combination.
1 | nat_to_sub(x, n, k)
|
x |
non-negative integers in the range |
n |
numerator of the binomial coefficient |
k |
denominator of the binomial coefficient |
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.
integer matrix whose columns give the combinadics of x
.
McCaffrey, J. D. "Generating the mth lexicographical element of a mathematical combination." MSDN Library (2004).
1 2 3 4 5 6 7 8 9 10 11 12 | 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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.