Plus, forcats::fct_recode()
is also useful in recoding categorical variables, except that it keeps unmentioned levels as is. So the second solution is
gndr_all %>%
forcats::fct_explicit_na(na_level = "missing") %>%
forcats::fct_recode(female="1",
male="2",
other = "missing",
other = "4",
other = "5"
)