R-使用do.call以降序排序 [英] R - Ordering using do.call with descending order

查看:97
本文介绍了R-使用do.call以降序排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据用户输入对数据集进行排序. 用户输入将是一个char数组(具有列名),在下面称为cols.

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])),]

这很好.我也尝试添加排序方向(降序或升序),但我不断收到相同的错误:未使用的参数(降序= TRUE)".

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)".

使用列的char []时,有人可以帮助我设置排序方向吗?

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

推荐答案

我们可以将多余的参数放在list中,并用它连接数据集并使用do.call

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))),]

这篇关于R-使用do.call以降序排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆