Skip to content
Prev 123883 / 398498 Next

Howto sort dataframe columns by colMeans

Something like the following may do what you want:

R> mydata.sorted <- mydata[c(1, 1 + order(colMeans(mydata[-1]),
decreasing=TRUE))]
R> mydata.sorted
   time met.c met.a met.b
1 00:00    99    42    18
2 00:05    67    88    16
3 00:10    84    80    27

(Note that I'm assuming that your first variable in the data frame is
not one of the things you want to include in your sorting.)

Andy


From: Lynn Osburn
------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}