Learn R Programming

iNZightTools (version 2.0.1)

missing_to_cat: Convert missing values to categorical variables

Description

Turn <NA> in categorical variables into "(Missing)"; numeric variables will be converted to categorical variables where numeric values as "(Observed)" and NA as "(Missing)".

Usage

missing_to_cat(data, vars, names = NULL)

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

names

a character vector of names for the new variables

Author

Zhaoming Su

See Also

code

Examples

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

Run the code above in your browser using DataLab