vec2sym | R Documentation |
Reverse operation of upper.tri
or lower.tri
. Given a vector of
upper or lower triangular elements of a matrix
(optionally including the diagonal elements), returns the
corresponding symmetric matrix. The elements of the vector can be arranged by
column (the default) or by row.
vec2sym(x, lower = TRUE, byrow = FALSE)
x |
vector containing upper or lower triangular elements of a symmetric matrix. |
lower |
x is from the lower triangle (default = |
byrow |
the elements in x are ordered row-wise (default = |
Many thanks for the author of the patr1ckm
package for providing us this method,
Handy R functions,
enabling to revert an upper.tri
or lower.tri
operation.
Note that if x is a vector of the lower triagular elements given by column, this is equivalent to the upper triangular elements given by row. Similarly, if x is a vector of the lower triangular elements given by row, this is equivalent to the upper triangular elements given by column.
Symmetric matrix
patr1ckm
x <- c(1, 1, 1, 2, 2, 3)
check <- matrix(c(1, 1, 1, 1, 2, 2, 1, 2, 3), 3, 3)
identical(vec2sym(x, lower = TRUE, byrow = FALSE), check)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.