| as_factor | R Documentation |
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().
as_factor(x, ...)
## S3 method for class 'haven_labelled_defined'
as_factor(x, strip_attributes = TRUE, ...)
x |
A vector created with |
... |
Reserved for future extensions. |
strip_attributes |
Logical; should semantic metadata attributes
(such as |
Use strip_attributes = TRUE when flattening or preparing data for
external pipelines, but keep the default when working with defined
vectors directly.
A factor vector.
sex <- defined(
c(0, 1, 1, 0),
label = "Sex",
labels = c("Female" = 0, "Male" = 1)
)
as_factor(sex)
as_factor(sex, strip_attributes = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.