Learn R Programming

matrixNormal (version 0.1.1)

vec: 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)

Value

A vector with mn elements.

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.

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

Run this code
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.")
}

Run the code above in your browser using DataLab