Learn R Programming

itertools2 (version 0.1.1)

irep: Iterator that replicates elements of an iterable object

Description

Constructs an iterator that replicates the values of an object.

Usage

irep(object, times = 1, length.out = NULL, each = NULL)
irep_len(object, length.out = NULL)

Arguments

object
object to return indefinitely.
times
the number of times to repeat each element in object
length.out
non-negative integer. The desired length of the iterator
each
non-negative integer. Each element is repeated each times

Value

iterator that returns object

Details

This function is intended an iterable version of the standard rep function. However, as exception, the recycling behavior of rep is intentionally not implemented.

Examples

Run this code
it <- irep(1:3, 2)
unlist(as.list(it)) == rep(1:3, 2)

it2 <- irep(1:3, each=2)
unlist(as.list(it2)) == rep(1:3, each=2)

it3 <- irep(1:3, each=2, length.out=4)
as.list(it3)

Run the code above in your browser using DataLab