Skip to content
Prev 155134 / 398513 Next

binary order combinations

names <- sprintf("V%d", 1:4);
n <- length(names);
stopifnot(n <= 32); # Theoretical upper limit
x <- matrix(intToBits(1:(2^n-1)), ncol=2^n-1);
x <- x[1:n,,drop=FALSE];
keys <- apply(x, MARGIN=2, FUN=function(z) paste(names[as.logical(z)],
collapse=":"));
print(keys);

 [1] "V1"          "V2"          "V1:V2"       "V3"
 [5] "V1:V3"       "V2:V3"       "V1:V2:V3"    "V4"
 [9] "V1:V4"       "V2:V4"       "V1:V2:V4"    "V3:V4"
[13] "V1:V3:V4"    "V2:V3:V4"    "V1:V2:V3:V4"

/H
On Fri, Sep 5, 2008 at 8:23 AM, Dimitri Liakhovitski <ld7631 at gmail.com> wrote: