数据框排序 data.frame order

# sorting examples using the mtcars dataset
attach(mtcars)

# sort by mpg
newdata <- mtcars[order(mpg),]

# sort by mpg and cyl
newdata <- mtcars[order(mpg, cyl),]

#sort by mpg (ascending) and cyl (descending)
newdata <- mtcars[order(mpg, -cyl),]

detach(mtcars)

 

==============================

 

newdata <- mtcars[order(mtcars$mpg),]

 

==============================

dd[with(dd, order(-z, b)), ]
## sort by column Z and B

==============================
posted @ 2015-01-28 15:09  emanlee  阅读(3479)  评论(0编辑  收藏  举报