Description Usage Arguments Details Value Examples
Constructs an iterator that computes the given function f
using the
arguments from each of the iterables given in ...
.
1 |
f |
a function |
... |
multiple arguments to iterate through in sequence |
The iterator returned is exhausted when the shortest iterable in ...
is exhausted. Note that imap
does not recycle arguments as
Map
does.
The primary difference between istarmap
and
imap
is that the former expects an iterable object
whose elements are already grouped together, while the latter case groups the
arguments together before applying the given function. The choice is a matter
of style and convenience.
iterator that returns the values of object
along with the
index of the object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | pow <- function(x, y) {
x^y
}
it <- imap(pow, c(2, 3, 10), c(5, 2, 3))
as.list(it)
# Similar to the above, but because the second vector is exhausted after two
# calls to `nextElem`, the iterator is exhausted.
it2 <- imap(pow, c(2, 3, 10), c(5, 2))
as.list(it2)
# Another similar example but with lists instead of vectors
it3 <- imap(pow, list(2, 3, 10), list(5, 2, 3))
iterators::nextElem(it3) # 32
iterators::nextElem(it3) # 9
iterators::nextElem(it3) # 1000
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.