Learn R Programming

tensr (version 1.0.1)

collapse_mode: Collapse multiple modes into one mode.

Description

Given an array X and a vector of integers m, collapse_mode returns an array of lower order where the first mode indexes the modes indicated in m.

Usage

collapse_mode(X, m)

Arguments

X

An array whose modes we are collapsing.

m

A vector of integers giving the modes to collapse.

Value

If \(X\) is of order \(K\) and length(m) = q, then returns an array \(Y\) of order \(K - q + 1\), where the modes indicated in m are combined to be the first mode in \(Y\).

Details

Transforms an array into another array where the provided modes are collapsed into one mode. The indexing along this new mode is in lexicographical order of the indices of the collapsed modes. The collapsed mode is the first mode unless length(m) == 1, then collapse_mode simply returns X.

Examples

Run this code
# NOT RUN {
X <- array(rep(c(1, 2), 8), dim = c(2, 2, 2, 2))
X
#mode 1 is now mode 2, modes 2, 3, and 4 are combined to be mode 1.
collapse_mode(X, c(2, 3, 4))
collapse_mode(X, c(2, 4)) ## another example.
collapse_mode(X, 4) #returns X
# }

Run the code above in your browser using DataLab