[R] sorting matrix elements by given rownames and colnames

From: Albert Vilella <avilella_at_gmail.com>
Date: Tue 13 Jun 2006 - 21:45:06 EST


Hi all,

I would like to know if it is possible to sort the columns and rows in a matrix given a specified order of their colnames and rownames. For example:

I would like the original matrix:   

     RNO FRU ANG CEL DAR PTR

RNO 3.45 1.35  2.16 2.25 1.43 1.20
FRU 1.31  Inf  2.22 2.36 1.34 1.40
ANG 1.30 1.30 11.61 1.37 1.33 1.35
CEL 1.34 1.35  1.37  Inf 1.37 1.40
DAR 1.40 1.29  2.29 2.39 9.62 1.48
PTR 1.08 1.30  2.06 2.17 1.39 8.17

To be sorted in a top/down and left/right way in this order instead: "FRU","ANG","CEL","PTR","RNO","DAR".

Thanks in advance,

    Albert.



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 13 22:58:17 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 14 Jun 2006 - 00:15:07 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.