I want to mutate the chr columns into factors, but exclude the first 15 columns (some of which are chr). I can only seem to mutate everything with mutate(across(where(is.character))...
or mutate(across(.cols = -c(1:15))...
. Additionally, I want to save the changes into the dataset (%<>%
) so I cannot just select out 1:15 first. For example, how would you
starwars%<>% mutate_if(is.character, as.factor)
but excluding name
.
We may use
library(dplyr)
library(magrittr)
starwars %<>%
mutate(across(c(where(is.character),-(1:5)), factor))