ienumerate: Iterator that returns the elements of an object along with...

Description Usage Arguments Details Value Examples

View source: R/ienumerate.r

Description

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.

Usage

1
2
3
ienumerate(object)

ienum(object)

Arguments

object

object to return indefinitely.

Details

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:

index:

a counter

value:

the current value of object

ienum is an alias to ienumerate to save a few keystrokes.

Value

iterator that returns the values of object along with the index of the object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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)

itertools2 documentation built on May 30, 2017, 7:17 a.m.