How to label NA values to missing?

Hello! I have a variable for ethnicity in my dataset that is a factor. For those with no ethnicity recorded R automatically assigns NA. I would like to label this NA to "missing" and create a new variable in the dataset.

I have tried forcats and ifelse but none of these work.

Any suggestions?

Thanks in advance!

maybe try forcats again ?

f1 <- factor(c("a", "a", NA, NA, "a", "b", NA, "c", "a", "c", "b"))
table(f1,useNA = "always")

f2 <- forcats::fct_explicit_na(f1)
table(f2,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.