nth | R Documentation |
Returns the n
th item of an iteror
after advancing the
iteror n
steps ahead. If the iteror
is entirely consumed,
the argument or
is returned instead. That is, if either n >
length(iteror)
or n
is 0, then the iteror
is consumed.
nth(obj, n, or, ...)
obj |
an iterable. |
n |
The index of the desired element to return. |
or |
If the iteror finishes before retuning |
... |
passed along to iteror constructor. |
The nth element of the iteror or the result of forcing or
.
take consume collect
it <- iteror(1:10)
# Returns 5
nth(it, 5, NA)
it2 <- iteror(letters)
# Returns 'e'
nth(it2, 5, NA)
it3 <- iteror(letters)
# Returns default value of NA
nth(it3, 42, NA)
it4 <- iteror(letters)
# Returns default value of "foo"
nth(it4, 42, or="foo")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.