rray_split: Split an array along an axis

View source: R/split.R

rray_splitR Documentation

Split an array along an axis

Description

rray_split() divides x into contiguous arrays along an axis.

Using rray_combine() along the same axis reconstructs x.

Usage

rray_split(x, ..., axis, dimensions)

Arguments

x

An array.

...

These dots are for future extensions and must be empty.

axis

The axis to split along, given by position or by title.

dimensions

One of:

  • A single positive integer, used as the dimension of every array. It must evenly divide the dimension of x along axis.

  • A vector of positive (or zero) integers, giving the dimension of each array directly. They must sum to the dimension of x along axis.

Value

A list of arrays each with the same dimensions as x, except along axis.

Examples

x <- array(1:12, c(6, 2))

# Three arrays of two rows
rray_split(x, axis = 1, dimensions = 2)

# Arrays of one and five rows
rray_split(x, axis = 1, dimensions = c(1, 5))

# One array per column
rray_split(x, axis = 2, dimensions = 1)

# One array per column, by title
y <- rray_set_titles(x, c("row", "col"))
rray_split(y, axis = "col", dimensions = 1)

# Arrays of dimension zero are allowed in the explicit form
rray_split(x, axis = 2, dimensions = c(0, 2))

# Splitting and combining along the same axis are inverses
rray_combine(!!!rray_split(x, axis = 1, dimensions = 3), .axis = 1)

rray documentation built on Nov. 17, 2026, 5:07 p.m.