izip_longest: Iterator that iterates through several iterables...

Description Usage Arguments Details Value Examples

View source: R/izip-longest.r

Description

The resulting iterator aggregates elements from each of the iterables into a list from each iteration. Used for lock-step iteration over several iterables at a time.

Usage

1
izip_longest(..., fill = NA)

Arguments

...

multiple arguments to iterate through in sequence

fill

the value used to replace missing values when the iterables in ... are of uneven length

Details

Although similar to izip, missing values are replaced with fill if the iterables are of uneven length, and Iteration continues until the longest iterable is exhausted.

Value

iterator that iterates through each argument in sequence

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
it <- izip_longest(x=1:3, y=4:6, z=7:9)
iterators::nextElem(it) # list(x=1, y=4, z=7)
iterators::nextElem(it) # list(x=2, y=5, z=8)
iterators::nextElem(it) # list(x=3, y=6, z=9)

it2 <- izip_longest(1:3, 4:8)
iterators::nextElem(it2) # list(1, 4)
iterators::nextElem(it2) # list(2, 5)
iterators::nextElem(it2) # list(3, 6)
iterators::nextElem(it2) # list(NA, 7)
iterators::nextElem(it2) # list(NA, 8)

it3 <- izip_longest(1:2, 4:7, levels(iris$Species), fill="w00t")
iterators::nextElem(it3) # list(1, 4, "setosa")
iterators::nextElem(it3) # list(2, 5, "versicolor")
iterators::nextElem(it3) # list("w00t", 6, "virginica")
iterators::nextElem(it3) # list("w00t", 7, "w00t")

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