a2v {str2str}R Documentation

(3D+) Array to (Atomic) Vector

Description

a2v converts a matrix to a (atomic) vector. The benefit of m2v over as.vector or c is that 1) the vector can be formed along rows any sequence of dimensions and 2) the dimnames from a can be used for the names of the returned vector.

Usage

a2v(a, along = ndim(a):1, use.dimnames = TRUE, sep = "_", check = TRUE)

Arguments

a

3D+ array.

along

numeric vector of length = ndim(a) that contains the integers 1:ndim(a) specifying the order which the array elements should be concatenated. For example, with a 3D array, 3:1 (default) specifies to split the array by layers first, then columns, and then rows. See examples.

use.dimnames

logical vector of length 1 that specifies whether the dimnames of a should be used to create the names for the returned vector. If FALSE, the returned vector will have NULL names. If TRUE, then each element's name will be analogous to paste(dimnames(a)[[1L]][i], dimnames(a)[[2L]][j], dimnames(a)[[3L]][k], ..., sep = sep). If a does not have dimnames, then they will be replaced by dimension positions.

sep

character vector of length 1 specifying the string that will separate the dimnames from each dimension in the naming scheme of the return object. Note, sep is not used if use.dimnames = FALSE.

check

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

Value

(atomic) vector of length = length(a) where the order of elements from a has been determined by along and the names determined by the use.dimnames, dimnames(a), and sep.

Examples

a2v(HairEyeColor) # layers, then columns, then rows (default)
a2v(HairEyeColor, along = c(3,1,2)) # layers, then rows, then columns
a2v(HairEyeColor, along = 1:3) # rows, then columns, then layers
a2v(HairEyeColor, along = 1:3, use.dimnames = FALSE)

[Package str2str version 1.0.0 Index]