take | R Documentation |
Returns the first n
elements of an iterable object
as a list.
If n
is larger than the number of elements in object
, the
entire iterator is consumed.
take(obj, n = 1, mode = "list", ...)
## Default S3 method:
take(obj, n = 1, mode = "list", ...)
## S3 method for class 'iteror'
take(obj, n = 1, mode = "list", ...)
obj |
An iterable object. |
n |
The maximum number of elements to extract from the iteror. |
mode |
The mode of vector to return. |
... |
Further arguments may be passed along to the iteror constructor. |
A function take
first appeared in package itertools2
.
It is basically an alias for as.list but defaults to n=1.
a list of the first n
items of the iterable
obj
concat as.vector.iteror
as.vector.iteror
take(1:10, 3) # 1 2 3
take(icount(), 10) # 1:10
take(icount(5), 10) # 1 2 3 4 5
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.