vec2mat: Convert a Vector into a Square Matrix

View source: R/vec2mat.r

vec2matR Documentation

Convert a Vector into a Square Matrix

Description

Function to convert a vector into a square matrix by filling up the lower triangular part of the matrix.

Usage

vec2mat(x, diag=FALSE, corr=!diag, dimnames)

Arguments

x

a vector of the correct length.

diag

logical to specify whether the vector also contains the diagonal values of the lower triangular part of the matrix (the default is FALSE).

corr

logical to specify whether the diagonal of the matrix should be replaced with 1's (the default is to do this when diag=FALSE).

dimnames

optional vector of the correct length with the dimension names of the matrix.

Details

The values in x are filled into the lower triangular part of a square matrix with the appropriate dimensions (which are determined based on the length of x). If diag=TRUE, then x is assumed to also contain the diagonal values of the lower triangular part of the matrix. If corr=TRUE, then the diagonal of the matrix is replaced with 1's.

Value

A matrix.

Author(s)

Wolfgang Viechtbauer wvb@metafor-project.org https://www.metafor-project.org

Examples

vec2mat(1:6, corr=FALSE)
vec2mat(seq(0.2, 0.7, by=0.1), corr=TRUE)
vec2mat(1:10, diag=TRUE)
vec2mat(1:6, corr=FALSE, dimnames=c("A","B","C","D"))

metafor documentation built on May 29, 2024, 7:44 a.m.