Skip to contents

Converts a defined() vector with value labels into a factor using haven::as_factor(). This allows categorical defined vectors to behave like standard factors in models and plotting.

Usage

as_factor(x, ...)

Arguments

x

A vector created with defined().

...

Reserved for future extensions; not used.

Value

A factor vector with levels derived from the value labels.

Examples

sex <- defined(
  c(0, 1, 1, 0),
  label = "Sex",
  labels = c("Female" = 0, "Male" = 1)
)
as_factor(sex)
#> [1] Female Male   Male   Female
#> Levels: Female Male