as_category {madshapR}R 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)))


}


[Package madshapR version 1.1.0 Index]