Skip to content
Prev 87189 / 398506 Next

Sorting a dataframe by one column?

mtb954 mtb954 wrote:
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)),]