[R] sort by column and row names

Phil Spector spector at stat.berkeley.edu
Fri Feb 18 00:35:49 CET 2011


Jim -
    I believe

dat[order(rownames(dat)),order(colnames(dat))]

is what you are looking for.
 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Thu, 17 Feb 2011, Jim Moon wrote:

> Hello, All,
>
> How can one sort on column and row names.  For example:
>
> How can this
> X1   X3   X2
> X1   1     0      0
> X3   0     1      0
> X2   0     0      1
>
> become this?
> X1   X2   X3
> X1   1     0      0
> X2  0     1      0
> X3   0     0      1
>
>
> Thank you for your time!
>
> Jim
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list