I am recoding a variable in R with the case_when function, changing only some of the values according to a set of rules, but when I print the new variable, the values I didn't include in the case_when function also change.
The variable I want to recode is a mixed variable that has character and numeric values. I am using the case_when function to transform the character values into numeric. The case is that when I print the new variable (expecting to get the old numeric values plus the new numeric values), the old numeric values also have changed.
Below there is the code I'm using..
pobgit_p %>%
mutate(P57_2_num = case_when(
P57_2 == "No" ~ 0,
P57_2 == "NS" ~ 0,
P57_2 == "NC" ~ 0,
))
I don't get what I am doing wrong.
Many thanks in advance :)