R - Ordering using do.call with descending order
Asked Answered
R

1

2

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?

Rivulet answered 12/10, 2016 at 16:55 Comment(1)
Try dataset1[do.call('order', c(dataset1[cols], list(decreasing=TRUE))),]Trimerous
T
5

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))),]
Trimerous answered 12/10, 2016 at 17:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.