isplitVector {itertools} | R Documentation |
Create an iterator that splits a vector
Description
Create an iterator that splits a vector into smaller pieces.
You can specify either the number of pieces, using the chunks
argument, or the maximum size of the pieces, using the chunkSize
argument.
Usage
isplitVector(x, ...)
Arguments
x |
Vector to iterate over. Note that it doesn't need to be an atomic vector, so a list is acceptable. |
... |
Passed as the second and subsequent arguments to
|
Value
An iterator that returns vectors of the same type as x
with one
or more elements from x
.
See Also
Examples
# Split the vector 1:10 into "chunks" with a maximum length of three
it <- ihasNext(isplitVector(1:10, chunkSize=3))
while (hasNext(it)) {
print(nextElem(it))
}
# Split the vector "letters" into four chunks
it <- ihasNext(isplitVector(letters, chunks=4))
while (hasNext(it)) {
print(nextElem(it))
}
# Get the first five elements of a list as a list
nextElem(isplitVector(as.list(letters), chunkSize=5))
[Package itertools version 0.1-3 Index]