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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.