| enum | R Documentation |
Create an enumeration to be used instead of arbitrary values in code. In some languages (C, C++, Python, etc.), enum (or enumeration) is a data type that consists of integer constants and is ideal in contexts where a variable can take on only one of a limited set of possible values (e.g. day of the week). Since R programming language natively doesn't support enumeration, the current function provides a way to create them using lists.
enum(enumValues)
enumValues |
A vector or a list of comma-separated constants to use for creating the enum. Optionally, these can be named constants. |
An enumerated list.
Other enumeration-helpers:
enumGetKey(),
enumGetValue(),
enumHasKey(),
enumKeys(),
enumPut(),
enumRemove(),
enumValues()
# Without predefined values
Color <- enum(c("Red", "Blue", "Green"))
Color
myColor <- Color$Red
myColor
# With predefined values
Symbol <- enum(c(Diamond = 1, Triangle = 2, Circle = 2))
Symbol
mySymbol <- Symbol$Diamond
mySymbol
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.