In case of shuffling and vectors that cannot be chunked evenly, it is chosen randomly which levels / chunks will receive 1 element less. If you do not shuffle, always the last chunks will receive 1 element less.
Arguments
- x
[ANY]
Vector, list or other type supported bysplit.- chunk.size
[
integer(1)]
Requested number of elements in each chunk. Cannot be used in combination withn.chunksorprops. Ifxcannot be evenly chunked, some chunks will have less elements.- n.chunks
[
integer(1)]
Requested number of chunks. If more chunks than elements inxare requested, empty chunks are dropped. Can not be used in combination withchunks.sizeorprops.- props
[
numeric]
Vector of proportions for chunk sizes. Empty chunks may occur, depending on the length ofxand the given proportions. Cannot be used in combination withchunks.sizeorn.chunks.- shuffle
[
logical(1)]
Shufflex? Default isFALSE.
Examples
xs = 1:10
chunk(xs, chunk.size = 3)
#> [[1]]
#> [1] 1 2 3
#>
#> [[2]]
#> [1] 4 5 6
#>
#> [[3]]
#> [1] 7 8
#>
#> [[4]]
#> [1] 9 10
#>
chunk(xs, n.chunks = 2)
#> [[1]]
#> [1] 1 2 3 4 5
#>
#> [[2]]
#> [1] 6 7 8 9 10
#>
chunk(xs, n.chunks = 2, shuffle = TRUE)
#> [[1]]
#> [1] 1 2 6 7 9
#>
#> [[2]]
#> [1] 3 4 5 8 10
#>
chunk(xs, props = c(7, 3))
#> [[1]]
#> [1] 1 2 3 4 5 6 7
#>
#> [[2]]
#> [1] 8 9 10
#>