(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)
Run the code above in your browser using DataLab