I was trying to recode a column with two values using dplyr.
name <- c("John", "Clara", "Smith")
sex <- c(1,2,1)
age <- c(30,32,54)
create a new dataframe from scratch
df <- data.frame(name, sex, age)
I used dplyr functions mutate and recode to change the values 1 & 2 to “Male” and “Female”.
df %>% mutate (sex= recode(sex, 1
= "Male", 2
= "Female"))
However, I got the following error message and wondering how I can fix this.
Error: Problem with mutate()
input sex
.
x unused arguments (1
= "Male", 2
= "Female")
i Input sex
is recode(sex,
1= "Male",
2 = "Female")
.
Backtrace:
9. dplyr::mutate(., sex = recode(sex, 1
= "Male", 2
= "Female"))
11. dplyr:::mutate_cols(.data, ...)
Thanks for your help