Learn R Programming

matlib (version 0.9.6)

symMat: Create a Symmetric Matrix from a Vector

Description

Creates a square symmetric matrix from a vector.

Usage

symMat(x, diag = TRUE, byrow = FALSE, names = FALSE)

Value

A symmetric square matrix based on column major ordering of the elements in x.

Arguments

x

A numeric vector used to fill the upper or lower triangle of the matrix.

diag

Logical. If TRUE (the default), the diagonals of the created matrix are replaced by elements of x; otherwise, the diagonals of the created matrix are replaced by "1".

byrow

Logical. If FALSE (the default), the created matrix is filled by columns; otherwise, the matrix is filled by rows.

names

Either a logical or a character vector of names for the rows and columns of the matrix. If FALSE, no names are assigned; if TRUE, rows and columns are named X1, X2, ... .

Author

Originally from metaSEM::vec2symMat, Mike W.-L. Cheung <mikewlcheung@nus.edu.sg>; modified by Michael Friendly

Examples

Run this code
symMat(1:6)
symMat(1:6, byrow=TRUE)
symMat(5:0, diag=FALSE)

Run the code above in your browser using DataLab