I have a long list of variables that I want to convert to factors. So, I did this:
factor_df <- original_df %>%
select(PhoneService:PaymentMethod) %>%
map(as.factor)
I get all the variables from PhoneService to PaymentMethod as factors.
How do I make this factor_df to attach to original_df again, so that the original_df has all the appropriate data types?
original_df %>%
mutate_at(vars(PhoneService:PaymentMethod), as.factor)
The dplyr::mutate_at() function allows you to specify which variables or vars() you wish to apply a single function or multiple functions with funs().
Source: https://dplyr.tidyverse.org/reference/summarise_all.html
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