Learn R Programming

merTools (version 0.6.2)

superFactor: Create a factor with unobserved levels

Description

Create a factor variable and include unobserved levels for compatibility with model prediction functions

Usage

superFactor(x, fullLev)

Value

a factor variable with all observed levels of x and all levels of x in fullLev

Arguments

x

a vector to be converted to a factor

fullLev

a vector of factor levels to be assigned to x

Examples

Run this code
# \donttest{
regularFactor <- c("A", "B", "C")
regularFactor <- factor(regularFactor)
levels(regularFactor)
# Now make it super
newLevs <- c("D", "E", "F")
regularFactor <- superFactor(regularFactor, fullLev = newLevs)
levels(regularFactor) # now super
# }

Run the code above in your browser using DataLab