[R-SIG-Mac] Sorting each column of a matrix independently
Ken Beath
ken at kjbeath.com.au
Thu Oct 14 10:26:55 CEST 2010
This question should be directed to R-Help
Anyway, sorted <- apply(unsorted,2,sort) should do it.
Ken
On 14/10/2010, at 7:06 PM, Desmond Lim wrote:
> 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
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>
More information about the R-SIG-Mac
mailing list