enum {inum} | R 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
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)
[Package inum version 1.0-5 Index]