vec2sym: Convert vector to symmetric matrix

Description Usage Arguments Details Value Examples

Description

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.

Usage

1
vec2sym(x, diagonal = NULL, lower = TRUE, byrow = FALSE)

Arguments

x

vector containing upper or lower triangular elements of a symmetric matrix

lower

x is from the lower triangle (default = TRUE)

byrow

the elements in x are ordered row-wise (default = FALSE)

If

NULL, x contains diagonal elements. Otherwise a value or vector of the appropriate length to be placed on the diagonal.

Details

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.

Value

Symmetric matrix

Examples

1
2
3
4
5
6
x <- c(1,1,1,2,2,3)
check <- matrix(c(1,1,1,1,1,1,2,2,1,2,1,3,1,2,3,1),4,4) 
identical(vec2sym(x,diag=1,lower=T,byrow=F), check)
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=T,byrow=F),check)

patr1ckm/patr1ckm documentation built on May 24, 2019, 8:21 p.m.