irep {itertools2} | R Documentation |
Constructs an iterator that replicates the values of an object
.
irep(object, times = 1, length.out = NULL, each = NULL)
irep_len(object, length.out = NULL)
object |
object to return indefinitely. |
times |
the number of times to repeat each element in |
length.out |
non-negative integer. The desired length of the iterator |
each |
non-negative integer. Each element is repeated |
This function is intended an iterable version of the standard
rep
function. However, as exception, the recycling
behavior of rep
is intentionally not implemented.
iterator that returns object
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)