I am trying to do something very simple, and yet can't figure out the right way to specify. I simply want to exclude some named columns from mutate_at
. It works fine if I specify position, but I don't want to hard code positions.
For example, I want the same output as this:
mtcars %>% mutate_at(-c(1, 2), max)
But, by specifying mpg
and cyl
column names.
I tried many things, including:
mtcars %>% mutate_at(-c('mpg', 'cyl'), max)
Is there a way to work with names and exclusion in mutate_at
?
You can use vars
to specify the columns, which works the same way as select()
and allows you to exclude columns using -
:
mtcars %>% mutate_at(vars(-mpg, -cyl), max)
One option is to pass the strings inside one_of
mtcars %>%
mutate_at(vars(-one_of("mpg", "cyl")), max)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With