Recoding using mutate in tidyverse

Hi again,
I was trying to recode a variable which has 0,1,2 to yes and no using

home_filter<- ckd %>% na.omit() %>% select(`filter home`) %>% mutate(`filter home`=recode(`filter home`, 1 = "no", 2 = "yes", 0 = "no"))

But error comes.Then I tried

home_filter<- ckd %>% na.omit() %>% select(`filter home`) %>% mutate(`filter home`=recode(`filter home`, "1" = "no", "2" = "yes", "0" = "no"))

Then only 4 is recoded. Why is this happening

Try filter_home or quote to deal with the embedded space

nope I have had the backsticks.It was not copied here

See the FAQ: How to do a minimal reproducible example rprex for beginners.

Doesnot answer my question. Anyway

As a forum moderator I was able to edit your post with triple backticks as recommended by the FAQ you were linked to. The rationale here is that it's better to share your code than a distortion of your code...

1 Like

I recommend starting with understanding your data type, (and sharing that with us)
and understanding the values you have (and sharing that with us)
i.e.

class(ckd$`filter home`)
table(ckd$`filter home`,useNA = "always")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.