[R] How to "Pack" a matrix

Guenther, Cameron Cameron.Guenther at MyFWC.com
Tue Sep 26 20:08:22 CEST 2006


Hello,
Suppose I have a matrix a where

a=		sp1	sp2	sp3	sp4	sp5	sp6
	site1	1	0	1	1	0	1
	site2	1	0	1	1	0	1
	site3	1	1	1	1	1	1
	site4	0	1	1	1	0	1
	site5	0	0	1	0	0	1
	site6	0	0	1	0	1	0

And I want to pack that matrix so that the upper left corner contains
most of the ones and the bottom right corner contains most of the zeros
so that matrix b is

b= 		sp3	sp6	sp4	sp1	sp2	sp5
	site1	1	1	1	1	0	0
	site2	1	1	1	1	0	0
	site3	1	1	1	1	1	1
	site4	1	1	1	0	1	0
	site5	1	1	0	0	0	0
	site6	1	0	0	0	0	1

Can any of you help me with some code to accomplish this?  I have tried
different forms of order and can't seem to figure it out.  Basically I
want to order the matrix by both the rows and columns.

Thank you for your help.
Cam

Cameron Guenther, Ph.D. 
Associate Research Scientist
FWC/FWRI, Marine Fisheries Research
100 8th Avenue S.E.
St. Petersburg, FL 33701
(727)896-8626 Ext. 4305
cameron.guenther at myfwc.com



More information about the R-help mailing list