Last data update: 2014.03.03

R: Lower/Upper Triangle Elements of a Matrix
Tri2MR Documentation

Lower/Upper Triangle Elements of a Matrix

Description

Lower/Upper triangle elements of a matrix or forms a matrix from a vector of lower/upper triangle elements

Usage

Tri2M(x, lower.tri = TRUE, reverse = TRUE, diag = TRUE)

Arguments

x

Matrix or vector

lower.tri

If x is a matrix then the lower triangle (TRUE) or upper triangle FALSE elements (including diagonal elements) are returned. If x is a vector a matrix is formed under the assumption that x are the lower triangle (TRUE) or upper triangle (FALSE) elements.

reverse

logical: ifTRUE a symmetric matrix is formed, if FALSE the remaining triangle is left as zeros.

diag

logical: ifTRUE diagonal elements are included.

Value

numeric or matrix

Author(s)

Jarrod Hadfield j.hadfield@ed.ac.uk

Examples

M<-rIW(diag(3), 10)
x<-Tri2M(M)
x
Tri2M(x, reverse=TRUE)
Tri2M(x, reverse=FALSE)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(MCMCglmm)
Loading required package: Matrix
Loading required package: coda
Loading required package: ape
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MCMCglmm/Tri2M.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Tri2M
> ### Title: Lower/Upper Triangle Elements of a Matrix
> ### Aliases: Tri2M
> ### Keywords: manip
> 
> ### ** Examples
> 
> M<-rIW(diag(3), 10)
> x<-Tri2M(M)
> x
[1]  1.40472169 -0.05231208  0.08563669  1.52951420 -0.16925075  0.54069877
> Tri2M(x, reverse=TRUE)
            [,1]        [,2]        [,3]
[1,]  1.40472169 -0.05231208  0.08563669
[2,] -0.05231208  1.52951420 -0.16925075
[3,]  0.08563669 -0.16925075  0.54069877
> Tri2M(x, reverse=FALSE)
            [,1]       [,2]      [,3]
[1,]  1.40472169  0.0000000 0.0000000
[2,] -0.05231208  1.5295142 0.0000000
[3,]  0.08563669 -0.1692507 0.5406988
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>