[R] Order a matrix

Lisa lisajca at gmail.com
Tue May 24 21:00:20 CEST 2011


Dear all,

I just want to order a matrix using several columns in a matrix. For
example:

x <- matrix(sample(c(1:5), 60, replace = T), 10, 6).

If I order the matrix by the first two columns, I will do it like this:
 
x[order(x[, 1], x[, 2]), ]. 

But when I repeat this work many times and the columns will change each time
in a simulation study, how can I assign the arguments of order()? For
example, in the first iteration, the columns needing to order is the first
two columns, in the second iteration, the columns needing to order is the
first, second, and fourth column? ….

I would appreciate any help on this question. Thanks a lot.

Lisa


--
View this message in context: http://r.789695.n4.nabble.com/Order-a-matrix-tp3547923p3547923.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list