ienumerate {itertools2} | R Documentation |
Constructs an iterator that returns the elements of an object along with each
element's indices. Enumeration is useful when looping through an
object
and a counter is required.
ienumerate(object)
ienum(object)
object |
object to return indefinitely. |
This function is intended to follow the convention used in Python's
enumerate
function where the primary difference is that a list is
returned instead of Python's tuple
construct.
Each call to nextElem
returns a list with two
elements:
a counter
the current value of object
ienum
is an alias to ienumerate
to save a few keystrokes.
iterator that returns the values of object
along with the
index of the object.
set.seed(42)
it <- ienumerate(rnorm(5))
as.list(it)
# Iterates through the columns of the iris data.frame
it2 <- ienum(iris)
iterators::nextElem(it2)
iterators::nextElem(it2)
iterators::nextElem(it2)
iterators::nextElem(it2)
iterators::nextElem(it2)