# 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

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

相关文章:

  • 2021-12-09
  • 2021-10-31
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
猜你喜欢
  • 2022-12-23
  • 2021-12-31
  • 2021-11-09
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2022-03-14
相关资源
相似解决方案