如何对数据帧进行排序
问题描述:
我想将字符向量传递给数据帧以对其进行排序。我怎样才能做到这一点?我曾尝试以下如何对数据帧进行排序
headings.tosort <- c("mpg", "hp")
headings <- intersect(headings.tosort, names(mtcars))
mtcars[with(mtcars,order(headings)),]
mtcars[with(mtcars,order(mpg,hp)),]
我希望能够创建具有标题列表的向量进行排序,然后把它的数据帧。第一个表达式不起作用,但第二个表达式不能,所以我该如何解决这个问题?
答
我也许误解了你的问题,但我会做这样的:
mtcars[do.call(order, mtcars[, headings]), ]