Problem with recoding variables with dplyr [closed]
I am getting an error message when trying to recode the gender currently coded as 1 or 2 in my dataset to Male and Female.
This is the code I am using
nhanes.2017 <- Tchol_cleaned %>%
mutate(Sex = recode_factor(.x = Sex,
`1` = 'Male',
`2` = 'Female'))
The error I am getting
Error: Problem with `mutate()` column `Sex`. i `Sex = recode_factor(.x = Sex, `1` = "Male", `2` = "Female")`. x no applicable method for 'recode' applied to an object of class "c('labelled', 'integer')"
The Tchol_cleaned dataset https://ufile.io/fxw8h71v
It's kinda hard to say without data, but something like this should do the trick.
nhanes.2017 <- Tchol_cleaned %>%
mutate(Sex = case_when(1 ~ "Male",
2 ~ "Female"))