Learn R Programming

madness (version 0.1.0)

vec: vectorize a multidimensional array.

Description

Turn a multidimensional array into a (column) vector. Turn a (typically symmetric) matrix into a (column) vector of the lower triangular part. Or reverse these operations.

Usage

vec(x)

## S3 method for class 'madness': vec(x)

## S3 method for class 'array': vec(x)

vech(x, k = 0)

## S3 method for class 'array': vech(x, k = 0)

## S3 method for class 'madness': vech(x, k = 0)

ivech(x, k = 0, symmetric = FALSE)

## S3 method for class 'ANY': ivech(x, k = 0, symmetric = FALSE)

## S3 method for class 'madness': ivech(x, k = 0, symmetric = FALSE)

Arguments

x
a madness object or multidimensional array or matrix.
k
the diagonal from which to subselect.
symmetric
logical whether to put the array on the antidiagonal as well. Will throw an error if k > 0.

Value

  • a madness object or an array, of the vectorized array or the subselected part. For the inverse operations, promotes to a madness of a matrix, or a matrix.

See Also

reshapes, in particular tril.

Examples

Run this code
y <- matrix(rnorm(16),ncol=4)
sy <- y + t(y)
vy <- vec(sy)
vmy <- vec(madness(sy))
vhy <- vech(sy)
vmhy <- vech(madness(sy))

ivech(c(1,2,3))
ivech(c(1,2,3),-1)
ivech(c(1,2,3),-1,symmetric=TRUE)
ivech(c(1,2,3,4,5,6,7,8),1)

Run the code above in your browser using DataLab