> d<-data.frame(id=1:4,x=c(0.1,0.5,0.2,0),y=c(3,1,9,5)) > d id x y 1 1 0.1 3 2 2 0.5 1 3 3 0.2 9 4 4 0.0 5 > d[order(d$y),] id x y 2 2 0.5 1 1 1 0.1 3 4 4 0.0 5 3 3 0.2 9
On 2/6/07, XinMeng <[EMAIL PROTECTED]> wrote: > Hello sir: > How can I sort a dataframe by sorting one of its column? > > e.g. > > dataframe: > > id x y > a 0.1 3 > b 0.5 1 > c 0.2 9 > d 0 5 > > I want the dataframe sorted according to y accending,the result is: > > id x y > b 0.5 1 > a 0.1 3 > d 0 5 > c 0.2 9 > > > > Thanks a lot! > > My best > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.