与R的数据争用
我有一长串的变量要转换成因子。所以,我这样做了:与R的数据争用,r,dplyr,tidyverse,R,Dplyr,Tidyverse,我有一长串的变量要转换成因子。所以,我这样做了: factor_df <- original_df %>% select(PhoneService:PaymentMethod) %>% map(as.factor) 因子_df% 选择(电话服务:PaymentMethod)%>% 映射(作为因子) 我得到了从PhoneService到PaymentMethod的所有变量作为因子。 如何使该因子_df再次
factor_df <- original_df %>%
select(PhoneService:PaymentMethod) %>%
map(as.factor)
因子_df%
选择(电话服务:PaymentMethod)%>%
映射(作为因子)
我得到了从PhoneService到PaymentMethod的所有变量作为因子。如何使该
因子_df
再次附加到原始_df
,以便原始_df
具有所有适当的数据类型
original_df %>%
mutate_at(vars(PhoneService:PaymentMethod), as.factor)
dplyr::mutate_at()
函数允许您指定希望使用funs()应用单个函数或多个函数的变量或vars()
资料来源:
是否要对所有字符变量进行转换?如果是,请参阅了解mutate\u If
的用法。或者,查看mutate\u at
以仅转换特定列