[R] inverse lexicographical ordering

Evgenia evgts at aueb.gr
Sat Feb 20 11:09:53 CET 2010

Thanks for your help.
Finally I found the solution to this problem for any matrix without having
to know its number of columns
I write it down in case someone else needed it.

#Creation of b matrix

   b <- matrix(0, 2^ncol, ncol)
     for (i in 1:ncol)
         b[, ncol+1-i] <- rep(rep(c(0,1),c(2^(i-1),2^(i-1))),2^(ncol-i))


mat <- b[ ,ncol(b):1 ] ( reverse columns making last first, etc)
b[do.call("order", split(mat, col(mat))),]

View this message in context: http://n4.nabble.com/inverse-lexicographical-ordering-tp1561930p1562709.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list