Learn R Programming

reporttools (version 1.1.3)

NAtoCategory: Change NAs in a factor into a category

Description

Extract all the missing values in a factor variable and turn them into a separate category.

Usage

NAtoCategory(fact, label = "missing")

Arguments

fact

Factor variable.

label

Label to be given to the missing valus.

Value

Updated factor variable.

Examples

Run this code
# NOT RUN {
set.seed(1977)
fact <- factor(sample(c(round(runif(10, 1, 3)), rep(NA, 10))), levels = 1:3, 
    labels = c("no", "maybe", "yes"))
NAtoCategory(fact)
# }

Run the code above in your browser using DataLab