Chunk a vector into a list of vectors of roughly equal length.

chunk(
  x,
  chunk_count = NULL,
  chunk_max_length = NULL,
  method = c("seq", "mod", "rand")
)

chunk_int(
  n,
  chunk_count = NULL,
  chunk_max_length = NULL,
  method = c("seq", "mod", "rand")
)

Arguments

x

The vector or list to be chunked.

method

The algorithm to use for chunking. "seq" _seq_uentially chunks x. "mod" creates chunks where original indices are alike after modulo arithmetic. "rand" specifies that x should be uniformly and randomly distributed across chunks.

n

The number of integers to chunk (i.e. chunk the sequence 1:n).

count

The number of chunks desired.

max_length

The maximum desired length of any chunk.

Value

For chunk, a list with x chunked across the list entries. For chunk_int, a list with the values 1:n chunked across the list entries.

Details

Exactly one of n_chunks and max_chunk_size should be NULL (to specify both as non-NULL is an error).