Re: [R] Sorting a dataframe by one column?

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Sat 25 Feb 2006 - 01:14:44 EST

mtb954 mtb954 wrote:
> Given the following dataframe:
>
> A=1:10
> B=(a-5)^2
> DATAFRAME=data.frame(A,B)
>
> How can I sort DATAFRAME increasing (or decreasing, for that matter)
> by B without making reference to A, or any other column?
>
> I've read ?order and ?sort but cannot seem to figure this out.

You should have tried RSiteSearch("sort dataframe") also, since there are many examples in the archives of R-help.

  A=1:10
  B=(A-5)^2
  mydata=data.frame(A,B)
  mydata[order(mydata$B),]
  mydata[rev(order(mydata$B)),]

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894

______________________________________________
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 Sat Feb 25 01:33:12 2006

This archive was generated by hypermail 2.1.8 : Sat 25 Feb 2006 - 03:08:48 EST