Skip to content
Prev 260790 / 398502 Next

Order a matrix

Try using do.call("order", listOfColumnsToSortBy), as in
  cols <- c(1,3,4)
  x[do.call("order", as.data.frame(x[,cols])), ]

To be really safe you should remove the names from the data.frame
produced by as.data.frame (in case they match the argument names
of order), as in
  x[do.call("order", unname(as.list(as.data.frame(x[,cols])))),]
or
  x[do.call("order", unname(split(x[,cols], col(x[,cols])))), ]

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com