Aliases: missingToCat
Keywords:
### ** Examples missing <- missingToCat(iris, vars = c("Species", "Sepal.Length")) cat(code(missing))
iris %>% tibble::add_column(Species_miss = forcats::fct_explicit_na(iris$Species, na_level = "missing"), .after = "Species") %>% tibble::add_column(Sepal.Length_miss = factor(ifelse(is.na(iris$Sepal.Length), "missing", "observed")), .after = "Sepal.Length")
head(missing)
Sepal.Length Sepal.Length_miss Sepal.Width Petal.Length Petal.Width Species 1 5.1 observed 3.5 1.4 0.2 setosa 2 4.9 observed 3.0 1.4 0.2 setosa 3 4.7 observed 3.2 1.3 0.2 setosa 4 4.6 observed 3.1 1.5 0.2 setosa 5 5.0 observed 3.6 1.4 0.2 setosa 6 5.4 observed 3.9 1.7 0.4 setosa Species_miss 1 setosa 2 setosa 3 setosa 4 setosa 5 setosa 6 setosa