isplitVector: Create an iterator that splits a vector

Description Usage Arguments Value See Also Examples

View source: R/isplitVector.R

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

1

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 idiv function. Currently, idiv accepts either a value for chunks or chunkSize.

Value

An iterator that returns vectors of the same type as x with one or more elements from x.

See Also

idiv

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 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))

itertools documentation built on May 30, 2017, 5:31 a.m.