I have a column Age containing strings in the form of "15 - 24"
, "25 - 34"
etc. I want to rename some of my rows and I use the following snippet.
d2$age <- ifelse(d2$age %in% c("35 - 44", "45 - 54", "55 - 64", "65 +"), "35 +", d2$age)
It works in the sense, that it successfully substitutes the values of the rows specified in the condition. But it also changes other rows where the condition is false. So I think something with the else clause is wrong. "15 - 24"
is changed to "2"
and "25 - 34"
is changed to "3"
. What did I do wrong?