as_factor() converts a defined() vector into a standard R
factor. If value labels are present, they are turned into factor levels
via haven::as_factor(). Otherwise, the underlying values are converted
with base::factor().
Usage
as_factor(x, ...)
# S3 method for haven_labelled_defined
as_factor(x, strip_attributes = TRUE, ...)
Value
A factor vector.
Arguments
x
A vector created with defined().
...
Reserved for future extensions.
strip_attributes
Logical; should semantic metadata attributes
(such as label, unit, definition, and
namespace) be removed from the returned vector?
Defaults to TRUE.
Details
Use strip_attributes = TRUE when flattening or preparing data for
external pipelines, but keep the default when working with defined
vectors directly.