[R] ordering columns in a data frame

David Freedman 3.14david at gmail.com
Wed Mar 10 13:37:48 CET 2010


I'm not sure what's incorrect about your result, but the following works:
d=data.frame(a=sample(letters[1:5],10,rep=T),b=rnorm(10),c=sample(1:10,10));
d
d[order(d$a,d$c),]

or, you can use orderBy:
lib(doBy)
orderBy(~a+b,data=d)  #use a - sign to sort in descending sequence

Did you leave off the tilde in your orderBy example?

hth
David Freedman, CDC Atlanta
-- 
View this message in context: http://n4.nabble.com/ordering-columns-in-a-data-frame-tp1587294p1587318.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list