I have a tibble and want to only do some mutation on selected columns. In the case below, all columns which have the word 'date' will be transformed by a function (as.Date()).
After I have performed some transformations on the selected columns, I want to get back all the columns from my tibble df.
Is there a way to do so?
df %>% select(contains('date')) %>% mutate_all(as.Date) %>% select(all)
Thanks
We can use mutate_at instead of select and then mutate_all. This would select only the columns of interest and modify those while keeping the others columns as such
library(dplyr)
df %>%
mutate_at(vars(contains('date')), as.Date)
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