enum | R Documentation |
'enum()' is creating a vector of integers to enumarate items in an object. It is particularly useful in the 'for(i in enum(object))' construct.
enum(x)
x |
Any object. |
The pattern 'for(i in 1:length(object))' is often found, but it fails in case 'length(object) == 0'! 'enum()' is indeed a synonym of 'seq_along()', but the later one is less expressive in the context.
[seq_along()]
enum(letters)
enum(numeric(0))
# Compare with:
1:length(numeric(0))
enum(NULL)
letters5 <- letters[1:5]
for (i in enum(letters5)) cat("letter", i, "=", letters5[i], "\n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.