2

I am getting this error using "arrange" from dplyr. I am trying to sort in descending order on 2 variables.

Error in `dplyr::arrange()`:
! `desc()` must be called with exactly one argument.

I have never had this problem before. Could there be a clash with another package? I installed the newest version of rlang today and since then I've had issues with "arrange".

Here is a sample of the data, as well as the code I am using:

df %>% 
  arrange(desc(year, amount))

year   amount    
2022     5    
2017     2     
2021     2         
2022     3       
2020     4         
2019     3      
2017     1    
2022     2 
2020     1

Should result in this. No?

year   amount
2022     5
2022     3
2022     2
2021     2
2020     4
2020     1
2019     3
2017     2
2017     1
bodega18
  • 596
  • 2
  • 13

1 Answers1

2

You can use this code:

df <- data.frame(year = c(2022, 2017, 2021, 2022, 2020, 2019, 2017, 2022, 2020),
                 amount = c(5, 2, 2, 3, 4, 3, 1, 2, 1))
         
         df %>% 
           arrange(desc(year))

Output:

year amount
2022      5
2022      3
2022      2
2021      2
2020      4
2020      1
2019      3
2017      2
2017      1

You should only mention one variable in desc()

Quinten
  • 35,235
  • 5
  • 20
  • 53