Learn R Programming

interfacer (version 0.3.3)

type.enum: Define a conformance rule to match a factor with specific levels.

Description

Define a conformance rule to match a factor with specific levels.

Usage

type.enum(..., .drop = FALSE, .ordered = FALSE)

Value

a function that can check and convert input into the factor with specified levels. This will re-level factors with matching levels but in a different order.

Arguments

...

the levels (no quotes, backticks if required)

.drop

should levels present in the data and not specified cause an error (FALSE the default) or be silently dropped to NA values (TRUE).

.ordered

must the factor be ordered

Examples

Run this code
f = type.enum(one,two,three)
f(c("three","two","one"))
f(factor(rep(1:3,5), labels = c("one","two","three")))

Run the code above in your browser using DataLab