微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

rstudio cloud integer64boolean转换为字符串

如何解决rstudio cloud integer64boolean转换为字符串

该数据集由12列(年龄,性别,收缩压,舒张压等)中的70,000条患者数据记录组成。所有列均为数字,12个整数和1个十进制数。

我正在尝试将列“ sex”从integer64转换为字符串,以便1可以代表女性“ F”,而2可以代表男性“ M”。 但是,当我尝试执行此操作时,the outputs are long strings

这是我的codes

的照片
# Let's change "1" and "2" to represent F and M: 
cleandf_nomiss <- na.omit(cleandf_sample)             # Remove null values
cleandf_nomiss$sex < toString(cleandf_nomiss$sex)     # Convert int64 to string
head(cleandf_nomiss)                                  # Check
cleandf_nomiss <- cleandf_sample %>%                  # Replace "1"="F" "2"="M"
  mutate(sex = recode_factor(sex,`1` = "F",`2` = "M"))

最后一个替换1 = F和2 = M的代码输出是这样的:

Error: Problem with `mutate()` input `sex`.
x no applicable method for 'recode' applied to an object of class "integer64"
ℹ Input `sex` is `recode_factor(sex,`2` = "M")`.
Run `rlang::last_error()` to see where the error occurred.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。