Book Image

Mastering Scientific Computing with R

Book Image

Mastering Scientific Computing with R

Overview of this book

Table of Contents (17 chapters)
Mastering Scientific Computing with R
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Triangular matrices


The tri.mat function in R can be used to create a triangular matrix. This function returns a matrix of true or false values, corresponding to the upper or lower triangle. The following commands return a lower triangular matrix of the cor.mat matrix:

triangle.matrix <- cor.mat
triangle.mat[upper.tri(triangle.matrix)] <- 
triangle.matrix

Here, we use upper.tri to identify the elements of the matrix that we wish to set to NA. In the case of this correlation matrix, the upper and lower triangles are identical, so retaining only half of the matrix makes sense.

We will also further discuss the decomposition of a square matrix into an upper and lower triangular matrix.