I'm trying to do a simple conditional with mutate.
The code should create a new variable called "gender" based on two variables from same dataframe.
sample <- data.frame(
client = c("john", "peter", "hanna", "lisa"),
id = c(100, 400, 650, 700),
resident = c('YES', 'YES', 'YES', 'NO'))
male_index <- as.vector(000:499)
female_index <- as.vector(500:999)
sample <- sample %>%
mutate(gender = ifelse(resident == "YES" & id %in% male_index, "Male",
mutate(gender = ifelse(resident == "YES" & id %in% female_index, "Female", "Female"))))
I'm getting the following error, which I don't understand. I guess it has something to do with SE. But I'm still not that familiar with R.
Error in mutate_impl(.data, dots) :
argument ".data" is missing, with no default
I don't get any issues if I run the code with a single mutate statement.