[R] sort matrix by sum of columns

From: Albert Vilella <avilella_at_gmail.com>
Date: Wed 21 Jun 2006 - 20:38:17 EST

Hi all,

I would like to know how can I sort the cols of a matrix by the sum of their elements.

a <- matrix(as.integer(rnorm(25,4,2)),10,5) colnames(a) = c("alfa","bravo","charlie","delta","echo")

I guess I should use colSums, and then rearrange the matrix somehow according to the result.

My idea is to display a "sorted" barplot:

barplot(a, horiz=TRUE, legend.text=T)

Thanks in advance,


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 Wed Jun 21 21:58:10 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 Thu 22 Jun 2006 - 02:11:54 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.