Learn R Programming

Xmisc (version 0.2.1)

vchunk: Chunk a vector into parts

Description

Chunk a vector into parts given the number of chunks or the max size of a chunk

Usage

vchunk(x, n = NULL, max.size = NULL, balance.size = TRUE, balance.order = FALSE)

Arguments

x
vector to chunk
n
numeric, the number of chunks
max.size
numeric, the maximal size of a chunk
balance.size
logical, as equal as possible. Whether return balanced chunks.
balance.order
logical, whether to balance the elements. Force balance.size to be TRUE. given their original orders.

Value

list

Examples

Run this code
vchunk(1:7,7)
vchunk(1:19,n=3)
vchunk(1:19,max.size=9) # size-balanced
vchunk(1:19,max.size=9,balance.size=FALSE) # size/order-unbalanced
vchunk(1:19,max.size=9,balance.size=FALSE,balance.order=TRUE) # order-balanced
vchunk(1:19,max.size=9,balance.order=TRUE) # size/order-balanced

Run the code above in your browser using DataLab