isplitVector: Create an iterator that splits a vector

Description Usage Arguments Value See Also Examples

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))

Example output

Loading required package: iterators
[1] 1 2 3
[1] 4 5 6
[1] 7 8
[1]  9 10
[1] "a" "b" "c" "d" "e" "f" "g"
[1] "h" "i" "j" "k" "l" "m" "n"
[1] "o" "p" "q" "r" "s" "t"
[1] "u" "v" "w" "x" "y" "z"
[[1]]
[1] "a"

[[2]]
[1] "b"

[[3]]
[1] "c"

[[4]]
[1] "d"

[[5]]
[1] "e"

itertools documentation built on May 2, 2019, 2:26 p.m.