How can I efficiently index all choose(m, k) subsets of m items taken k at a time? For example, with (m, k) = (3, 2), the subsets are (1, 2), (1, 3), and (2, 3). I'd like a function something like "index.subsets(subset, k, m)" that would return 1, 2 or 3 for these 3 subsets. Examples:

index.subsets(c(1,2), 2, 3) -> 1
index.subsets(c(1,3), 2, 3) -> 2
index.subsets(c(2,3), 2, 3) -> 3

index.subsets(c(1,2,3), 3, 5) -> 1
index.subsets(c(1,2,5), 3, 5) -> 3
index.subsets(c(3,4,5), 3, 5) -> 10

          Thanks.
Spencer Graves

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to