sort_factor: Create Sorted Factor

View source: R/factors.R

sort_factorR Documentation

Create Sorted Factor

Description

Set factor with sorted ascending unique values as levels. Also allows the user to explicitly set the reference level.

Usage

sort_factor(var, base.level = NULL, ...)

Arguments

var

Vector to convert to factor.

base.level

Reference level as a character string. Optional argument.

...

Additional arguments to pass to factor()

Value

A factor with levels in ascending order and a potential user-defined reference level.

Examples

no_ref <- sort_factor(c("e", "f", "z", "d", "a"))
with_ref <- sort_factor(c("e", "f", "z", "d", "a"), base.level = "z")

levels(no_ref)
levels(with_ref)


dmolitor/dmolitorUtils documentation built on Sept. 24, 2022, 6 a.m.