Learn R Programming

iNZightTools (version 1.13.0)

missingToCat: Convert missing values to categorical variables

Description

Turn <NA>'s into a "missing" character; hence numeric variables will be converted to categorical variables with any numeric values will be converted to "observed", and returns the result along with tidyverse code used to generate it.

Usage

missingToCat(.data, vars, names = paste0(vars, "_miss"))

Value

original dataframe containing new columns of the converted variables for the missing values with tidyverse code attached

Arguments

.data

a dataframe with the columns to convert its missing values into categorical

vars

a character vector of the variables in .data for conversion of missing values to categorical

names

a vector of names for the new variables

Author

Owen Jin

See Also

code

Examples

Run this code
missing <- missingToCat(iris, vars = c("Species", "Sepal.Length"))
cat(code(missing))
head(missing)

Run the code above in your browser using DataLab