[R-SIG-Mac] Sorting each column of a matrix independently

Desmond Lim limwenpin at gmail.com
Thu Oct 14 10:06:26 CEST 2010


Hi,

I have this matrix

unsorted$A with 5 columns (all numeric).

Currently I'm sorting the columns like this:

sorted$A[,1] <- sort(unsorted$A[,1])
sorted$A[,2] <- sort(unsorted$A[,2]) ...

I have tried doing

sorted$A <- unsorted$A[do.call(order, data.frame(unsorted$A)),] but it
sorts the first column then the 2nd column which it ties to the 1st
column, then the 3rd which is tied to the 2nd, etc. I need all the
columns to be independently sorted.

Any help is appreciated.

Desmond



More information about the R-SIG-Mac mailing list