Learn R Programming

metaSEM (version 1.2.4)

Diag: 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.

See Also

diag

Examples

Run this code
# NOT RUN {
v <- c("a", "b")
Diag(v)
# }

Run the code above in your browser using DataLab