Learn R Programming

statnet.common (version 4.10.0)

split.array: A split() method for array and matrix types on a margin.

Description

These methods split an array and matrix into a list of arrays or matrices with the same number of dimensions according to the specified margin.

Usage

# S3 method for array
split(x, f, drop = FALSE, margin = NULL, ...)

# S3 method for matrix split(x, f, drop = FALSE, margin = NULL, ...)

Arguments

x

A matrix or an array.

f, drop

See help for split(). Note that drop here is not for array dimensions: these are always preserved.

margin

Which margin of the array to split along. NULL splits as split.default, dropping dimensions.

...

Additional arguments to split().

Examples

Run this code

x <- diag(5)
f <- rep(1:2, c(2,3))
split(x, f, margin=1) # Split rows.
split(x, f, margin=2) # Split columns.

# This is similar to how data frames are split:
stopifnot(identical(split(x, f, margin=1),
          lapply(lapply(split(as.data.frame(x), f), as.matrix), unname)))

Run the code above in your browser using DataLab