Learn R Programming

BBmisc (version 1.2-200)

chunk: Chunk elements of vectors into blocks of nearly equal size.

Description

Chunk elements of vectors into blocks of nearly equal size.

Usage

chunk(x, chunk.size, n.chunks, shuffle = FALSE)

Arguments

x
[vector | list] Vector or list to chunk into blocks of nearly equal size.
chunk.size
[integer(1)] Preferred number of jobs in each chunk. Can not be used in combination with n.chunks
n.chunks
[integer(1)] Preferred number of chunks. Can not be used in combination with chunks.size
shuffle
[logical(1)] Shuffle the vector or list? Default is FALSE.

Value

  • [unnamed list] of chunks.

Examples

Run this code
xs <- 1:10
chunk(xs, chunk.size=3)
chunk(xs, n.chunks=2)
chunk(xs, n.chunks=2, shuffle=TRUE)

Run the code above in your browser using DataLab