unsortedFactor: Factor with Unsorted Levels

View source: R/unsortedFactor.R

unsortedFactorR Documentation

Factor with Unsorted Levels

Description

Casting factor() upon a (character) vector usually results in alphabetically ordered factor levels. Although this seems reasonable in most cases, the automated ordering of factor levels is seldomly desirable in the context of visualization, e.g. when working with tiled lattice or ggplot2 figures. This function returns a factor with levels ordered according to their first appearance in the supplied vector.

Usage

unsortedFactor(x, ...)

Arguments

x

A character vector with elements to converted to factor.

...

Additional arguments passed to factor().

Author(s)

Florian Detsch

Examples

mnth <- month.abb

## factor levels are being sorted
fc_mnth <- factor(mnth)
levels(fc_mnth)

## factor levels remain unsorted
fc_mnth2 <- unsortedFactor(mnth)
levels(fc_mnth2)


Orcs documentation built on Jan. 6, 2023, 5:14 p.m.