r - rstudio cloud integer64 (boolean) to string
问题描述
This dataset consists of 70,000 records of patients data in 12 columns, such as age, sex, systolic blood pressure, diastolic blood pressure, and etc. All columns are numerical, 12 integers and 1 decimal number.
I am trying to convert column "sex" from an integer64 to a string so that 1 can represent female "F" and 2 can represent male "M". However, when I try to do this, the outputs are long strings:
Here is a picture of my 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"))
The output for the last code to replace 1=F and 2=M is this:
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, `1` = "F", `2` = "M")`.
Run `rlang::last_error()` to see where the error occurred.
解决方案
推荐阅读
- python - 根据一列的连续值获取数据框的行
- ios - 如何以编程方式重新创建 iOS 共享到应用程序功能?
- javascript - macOS 上的 Javascript Things3 错误:无法转换类型
- sql - 更新 BQ 表中 5K 行的高效语法
- python - How to call the instance method of the parent class?
- ruby-on-rails - 尝试运行即将到来的数据库并由用户从前端保存的“ruby 代码”。(Ruby on Rails)
- mysql - 如何在nodeJS的mysql查询中将值推送到数组?
- python - 我的脚本单独工作,但不能作为一个函数,为什么?
- c++ - OpenGL 无法正确采样 2D 纹理
- python - 我们如何在 2 列的基础上比较两个不同的 csv 文件,并使用 pandas 从第二个 csv 文件中打印不匹配的行