could you please explain why the names(df) not working within dfplyr::arrange(), is there a way to make it work
nam <- names(mtcars)
mtcars2 <- mtcars %>% arrange(nam)
CodePudding user response:
With more than one column, we may use across
library(dplyr)
mtcars %>%
arrange(across(all_of(nam)))
There is a difference in the behavior of variadic input (...
) between select
and functions like mutate/arrange/summarise
#select
... - tidy-select - One or more unquoted expressions separated by commas. Variable names can be used as if they were positions in the data frame, so expressions like x:y can be used to select a range of variables.
#arrange (similar with mutate/filter)
... - data-masking- Variables, or functions of variables. Use desc() to sort a variable in descending order.