chunk {BBmisc} | R Documentation |
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.
chunk(x, chunk.size, n.chunks, props, shuffle = FALSE)
x |
[ANY] |
chunk.size |
[ |
n.chunks |
[ |
props |
[ |
shuffle |
[ |
[unnamed list
] of chunks.
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 4 7 8 10
##
## [[2]]
## [1] 2 3 5 6 9
chunk(xs, props = c(7, 3))
## [[1]]
## [1] 1 2 3 4 5 6 7
##
## [[2]]
## [1] 8 9 10