Learn R Programming

ngramr (version 1.7.4)

chunk: Chunk a vector or list

Description

chunk takes a vector (or list) and returns a list of chunks of (approximately) equal to a specified length.

Usage

chunk(x, len = NULL, n = NULL)

Arguments

x

vector of list

len

target length of chunks

n

number of chunks

Details

If n is specified, len is ignored and chunk returns a list of length n of "chunks" of x. Otherwise n is calculated to break the vector into chunks which are each approximately of length len. If both len and n are unspecified, chunk simply returns x.

Examples

Run this code
# NOT RUN {
chunk(letters, 10)
chunk(LETTERS, n = 3)

# }

Run the code above in your browser using DataLab