Learn R Programming

utile.tools (version 0.2.7)

calc_chunks: Calculate data chunk indices

Description

Calculates chunk indices of a data object for a given chunk size (number of items per chunk).

Usage

calc_chunks(x, size = 10, reverse = FALSE)

Value

An iterable list of row indices for each chunk of data.

Arguments

x

A data frame or vector.

size

An integer. The number of items (e.g. rows in a tibble) that make up a given chunk. Must be a positive integer. Caps out at data maximum.

reverse

A logical. Calculate chunks from back to front.

Examples

Run this code
# Create chunk map for a data frame
chunks <- calc_chunks(mtcars, size = 6)

# Iterate through chunks of data
for (chunk in chunks) print(paste0(rownames(mtcars[chunk,]), collapse = ', '))

Run the code above in your browser using DataLab