Creates a square symmetric matrix from a vector.
symMat(x, diag = TRUE, byrow = FALSE, names = FALSE)
A numeric vector used to fill the upper or lower triangle of the matrix.
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".
Logical. If FALSE
(the default), the created matrix is filled by columns;
otherwise, the matrix is filled by rows.
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
, ... .
A symmetric square matrix based on column major ordering of the elements in x
.
symMat(1:6)
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 2 4 5
#> [3,] 3 5 6
symMat(1:6, byrow=TRUE)
#> [,1] [,2] [,3]
#> [1,] 1 2 4
#> [2,] 2 3 5
#> [3,] 4 5 6
symMat(5:0, diag=FALSE)
#> [,1] [,2] [,3] [,4]
#> [1,] 1 5 4 3
#> [2,] 5 1 2 1
#> [3,] 4 2 1 0
#> [4,] 3 1 0 1