Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

chunk_vector

Chunk Vectors


Description

Chunk atomic vectors into parts of roughly equal size. chunk() takes a vector length n and returns an integer with chunk numbers. chunk_vector() uses base::split() and chunk() to split an atomic vector into chunks.

Usage

chunk_vector(x, n_chunks = NULL, chunk_size = NULL, shuffle = TRUE)

chunk(n, n_chunks = NULL, chunk_size = NULL, shuffle = TRUE)

Arguments

x

(vector())
Vector to split into chunks.

n_chunks

(integer(1))
Requested number of chunks. Mutually exclusive with chunk_size and props.

chunk_size

(integer(1))
Requested number of elements in each chunk. Mutually exclusive with n_chunks and props.

shuffle

(logical(1))
If TRUE, permutes the order of x before chunking.

n

(integer(1))
Length of vector to split.

Value

chunk() returns a integer() of chunk indices, chunk_vector() a list() of integer vectors.

Examples

x = 1:11

ch = chunk(length(x), n_chunks = 2)
table(ch)
split(x, ch)

chunk_vector(x, n_chunks = 2)

chunk_vector(x, n_chunks = 3, shuffle = TRUE)

mlr3misc

Helper Functions for 'mlr3'

v0.10.0
LGPL-3
Authors
Michel Lang [cre, aut] (<https://orcid.org/0000-0001-9754-0393>), Patrick Schratz [aut] (<https://orcid.org/0000-0003-0748-6624>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.