带有OR条件dplyr的mutate_if() [英] mutate_if() with OR conditions dplyr

查看:138
本文介绍了带有OR条件dplyr的mutate_if()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想将整数 double 变量转换为字符变量,
如何完成任务,我尝试了以下代码,但我确定这是一种错误的方法。

If I want to convert an integer or double variables to character variables, how can I accomplish the task, I tried the below code, but I am certain this is an incorrect way.

storms %>% mutate_if(c(is.integer | is.double),
                     .funs = as.character)


推荐答案

您可以使用此版本的 mutate_if

library(dplyr)
storms %>% mutate_if(~ is.double(.) | is.integer(.), as.character)

会将双精度或整数列转换为字符。

which would convert the double or integer columns to character.

这篇关于带有OR条件dplyr的mutate_if()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆