enum | R Documentation |
Elements of a vector are stored as a set of levels and an integer representing the enumeration.
enum(x)
x |
A vector. Currently, methods for factors, logicals, integers, and numeric vectors are implemented. |
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.
An object of class enum
. A value of 0
encodes NA
.
factor
(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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.