Diag: Matrix Diagonals

View source: R/Diag.R

DiagR Documentation

Matrix Diagonals

Description

Extract or replace the diagonal of a matrix, or construct a diagonal matrix with the same behaviors as diag prior to R-3.0.0.

Usage

Diag(x, ...)
Diag(x) <- value

Arguments

x

A matrix, vector or 1D array, or missing.

...

Optional dimensions (nrow and ncol) for the result when x is not a matrix.

value

Either a single value or a vector of length equal to that of the current diagonal. Should be of a mode which can be coerced to that of x.

Details

Started from R-3.0.0, diag(x) returns a numeric matrix with NA in the diagonals when x is a character vector. Although this follows what the manual says, this breaks the metaSEM. The Diag has the same functions as diag except that Diag(x) works for a character vector of x by returning a square matrix of character "0" with x as the diagonals.

Note

See http://r.789695.n4.nabble.com/Behaviors-of-diag-with-character-vector-in-R-3-0-0-td4663735.html for the discussion.

Author(s)

Mike W.-L. Cheung <mikewlcheung@nus.edu.sg>

See Also

diag

Examples

v <- c("a", "b")
Diag(v)

metaSEM documentation built on Aug. 10, 2023, 1:09 a.m.