powered by
This gives missing values an explicit factor level, ensuring that they appear in summaries and on plots.
fct_explicit_na(f, na_level = "(Missing)")
A factor (or character vector).
Level to use for missing values: this is what NAs will be changed to.
NA
f1 <- factor(c("a", "a", NA, NA, "a", "b", NA, "c", "a", "c", "b")) fct_count(f1) table(is.na(f1)) f2 <- fct_explicit_na(f1) fct_count(f2) table(is.na(f2))
Run the code above in your browser using DataLab