enum: Enumeration-type Representation of Vectors

View source: R/enum.R

enumR Documentation

Enumeration-type Representation of Vectors

Description

Elements of a vector are stored as a set of levels and an integer representing the enumeration.

Usage

  enum(x)

Arguments

x

A vector. Currently, methods for factors, logicals, integers, and numeric vectors are implemented.

Details

The unique elements of x are stored as a levels attribute to an integer representing the enumeration. levels and nlevels methods are available. This is essentially the same as factor where the levels can be arbitrary vectors, not just characters.

Value

An object of class enum. A value of 0 encodes NA.

See Also

factor

Examples


(ex <- enum(x <- gl(2, 2)))
all.equal(levels(ex)[ex], x)

(ex <- enum(x <- rep(c(TRUE, FALSE), 2)))
all.equal(levels(ex)[ex], x)

(ex <- enum(x <- rep(1:5, 2)))
all.equal(levels(ex)[ex], x)

(ex <- enum(x <- rep(1:5 + .5, 2)))
all.equal(levels(ex)[ex], x)

(ex <- enum(x <- c(NA, rep(1:5 + .5, 2))))
all.equal(c(NA, levels(ex))[unclass(ex) + 1L], x)


inum documentation built on March 31, 2023, 3:07 p.m.

Related to enum in inum...