enum: Enumeration-type Representation of Vectors

Description Usage Arguments Details Value See Also Examples

View source: R/enum.R

Description

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

Usage

1
  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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(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 Dec. 13, 2017, 1:03 a.m.