levels2: Levels of vector

View source: R/utils.R

levels2R Documentation

Levels of vector

Description

Extension of levels() function. If levels(x) is not NULL, it is returned. Otherwise, character representation of unique sorted values is returned (with NA treated based on na.last as in sort()).

Usage

levels2(x, na.last = TRUE)

Arguments

x

An object of interest.

na.last

Argument for controlling the treatment of NAs. See sort().

Examples

fac_vec <- factor(c("a", "b"), levels = c("a", "b", "c"))
levels2(fac_vec)

levels2(c(10, 1, 2, NA, 11))

comperes documentation built on March 7, 2023, 7:02 p.m.