Combinatronics
It’s easier in R if we look at these backwards.
Combinations
- Order doesn’t matter, so (1, 2) == (2, 1)
- \(\frac{n!}{k!(n-k)!}={n \choose k}\)
choose(n, k)
combn(x, m)
to generate matrix of combinations
Permutations
- Cares about order (so there are more)
- \(\frac{n!}{(n-k)!}={n \choose k}\cdot k!\)
choose(n, k) * factorial(k)
prod(n - (0:(k - 1)))
= more efficient