lm2a {str2str}R Documentation

List of Matrices to 3D Array

Description

lm2a converts a list of matrices to a 3D array where the list dimension becomes the third dimension of the array (layers). lm2a is a simple wrapper function for abind::abind.

Usage

lm2a(lm, dim.order = c(1, 2, 3), dimlab.list = NULL, check = TRUE)

Arguments

lm

list of matrices which each have the same dimensions.

dim.order

integer vector of length 3 specifying the order of dimensions for the returned array. The default is c(1,2,3) which means the rows of the matrices in lm is the first dimension (i.e., rows), the columns of the matrices in lm is the second dimension (i.e., columns), and the list elements of lm is the third dimension (i.e., layers).

dimlab.list

character vector of length 1 specifying the dimlabel for the list dimension.

check

logical vector of length 1 specifying whether to check the structure of the input arguments. For example, check whether lm is a list of matrices. This argument is available to allow flexibility in whether the user values informative error messages (TRUE) vs. computational efficiency (FALSE).

Value

3D array where the list elements of lm is now a dimension. The order of the dimensions is determined by the argument dim.order with dimnames specified by names(lm). The dimnames of the returned array is determined by the dimnames in lm[[1]] and names(lm).

Examples

lm <- asplit(HairEyeColor, MARGIN = 3L)
lm2a(lm) # default
lm2a(lm, dimlab.list = "Sex")
lm2a(lm, dim.order = c(3,1,2))
lm2a(lm, dim.order = c(3,1,2), dimlab.list = "Sex")

[Package str2str version 1.0.0 Index]