[R] index all subsets of k of m items?
Spencer Graves
spencer.graves at pdf.com
Fri Aug 1 12:56:19 CEST 2003
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
More information about the R-help
mailing list