首页 > 解决方案 > 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: the outputs are long strings

Here is a picture of my codes: 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.

标签: rbooleanint64

解决方案


推荐阅读