get_levels: Get Factor Levels

get_levelsR Documentation

Get Factor Levels

Description

Extracts the factor levels of a vector or returns the unique values if the vector is not a factor.

Usage

get_levels(x)

Arguments

x

a vector

Value

x vector

References

A character vector containing the levels of the factor/vector

Examples

data(adae, package = "tidyCDISC")

# Create levels based on VARN
varN_fctr_adae <- varN_fctr_reorder(adae)

# `adae` does not have factor but `varN_fctr_adae` does
levels(adae$RACE)
levels(varN_fctr_adae$RACE)

# `get_levels()` either creates the factor or retrieves it
get_levels(adae$RACE)
get_levels(varN_fctr_adae$RACE)

Biogen-Inc/tidyCDISC documentation built on April 22, 2023, 2:12 p.m.