Diag: Matrix Diagonals

Description Usage Arguments Details Note Author(s) See Also Examples

View source: R/Diag.R

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

1
2
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 <[email protected]>

See Also

diag

Examples

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

metaSEM documentation built on May 9, 2018, 5:04 p.m.