vec {matrixNormal}R Documentation

Stacks a Matrix using matrix operator "vec"

Description

Returns a column vector that stacks the columns of A, a m x n matrix.

Usage

vec(A, use.Names = TRUE)

Arguments

A

A matrix with m rows and n columns.

use.Names

Logical. If TRUE, the names of A are taken to be names of the stacked matrix. Default: TRUE.

Value

A vector with mn elements.

Note

  1. Unlike other 'vec()' functions on CRAN, matrixNormal version inherits names from matrices to their vectorized forms.

  2. vec() was adapted from Frederick Novomestky's matrixcalc. This function is edited so that it can take dimension names and return the matrix as a vector.

  3. These functions were used as accessories for other matrixNormal functions.

References

Magnus, J. R. and H. Neudecker (1999). Matrix Differential Calculus with Applications in Statistics and Econometrics. Second Edition, John Wiley, ed.

See Also

Other matrix: special.matrix, tr()

Examples

M <- matrix(c(4, 5, 6, 7, 8, 9), nrow = 3)
M
vec(M)
if (!requireNamespace("matrixcalc", quietly = TRUE)) {
# Compare vec from \pkg{matrixcalc} and new function.
matrixcalc::vec(M)
# The names are rownames(M):colnames(M) in that order.
# Very similar to matrixcalc but dimension names are different.
} else {
  message("you need to install the package matrixcalc to compare this example.")
}

[Package matrixNormal version 0.1.1 Index]