as_category: Validate and coerce any object as a categorical variable.

View source: R/experimental.R

as_categoryR Documentation

Validate and coerce any object as a categorical variable.

Description

[Experimental] Converts a vector object to a categorical object, typically a column in a data frame. The categories come from non-missing values present in the object and are added to an associated data dictionary (when present).

Usage

as_category(x)

Arguments

x

A vector object to be coerced to categorical.

Value

A vector with class haven_labelled.

See Also

haven::labelled()

Examples

{

library(dplyr)
mtcars <- tibble(mtcars)
as_category(mtcars[['cyl']])

head(mtcars %>% mutate(cyl = as_category(cyl)))


}


madshapR documentation built on May 29, 2024, 7:43 a.m.