Friday, October 2, 2009

order data frames in R

say data has read and prog as colums

data[order(read, prog), ]

this will order first by read then by prog

data[order(-read), ]

- reverses the order

** there can be conflicts if read is a variable outside of the data frame. Use data[order(data[,1]),] assuming read is column 1

from: http://www.ats.ucla.edu/stat/R/faq/sort.htm

1 comment:

MK said...

I wonder f with() would resolve the issue of one of the ordering variables being outside the data.frame... will have to check it out.

Contributors

google