R - Ordering using do.call with descending order

旧巷老猫 提交于 2019-12-08 09:45:56

问题


I want to order a dataset based on an user input. The user input will be a char array (of column name), called cols below.

dataset1[do.call('order', as.list(dataset1[cols])),]

This works fine. I'm trying to add the ordering direction (descending or ascending) too but I keep getting the same error: "unused argument (descending = TRUE)".

Anyone can help me setting the ordering direction while using a char[] of columns?


回答1:


We can place the extra argument in a list, concatenate the dataset with that and use do.call

dataset1[do.call('order', c(dataset1[cols], list(decreasing=TRUE))),]


来源:https://stackoverflow.com/questions/40004217/r-ordering-using-do-call-with-descending-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!