diag2vec: Extract Diagonal of a Matrix

Description Usage Arguments Details See Also Examples

View source: R/MxAlgebraFunctions.R

Description

Given an input matrix, diag2vec returns a column vector of the elements along the diagonal.

Usage

1

Arguments

x

an input matrix.

Details

Similar to the function diag, except that the input argument is always treated as a matrix (i.e., it doesn't have diag()'s functions of returning an Identity matrix from an nrow specification, nor to return a matrix wrapped around a diagonal if provided with a vector). To get vector2matrix functionality, call vec2diag.

See Also

vec2diag

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
diag2vec(matrix(1:9, nrow=3))
#      [,1]
# [1,]    1
# [2,]    5
# [3,]    9

diag2vec(matrix(1:12, nrow=3, ncol=4))
#      [,1]
# [1,]    1
# [2,]    5
# [3,]    9

OpenMx documentation built on Nov. 17, 2017, 6:50 a.m.