Convert a matrix into a lower triangular matrix using R

In this article, we will explore various methods to convert a matrix into a lower triangular matrix in R programming language.

What is a matrix?

A matrix is a two-dimensional rectangular data structure, which is a collection of rows and columns. Representation of rows is horizontal and columns are vertical. A matrix can contain data of the same type such as numeric, character, and, logic. It is possible to perform various operations on matrices. These matrixes are very similar to the vectors but differ in their dimensionalities. Using the function ‘matrix()’ can create the matrix.

Converting a matrix into various types of lower triangular matrices

R language offers different types of lower triangular matrices. In the lower triangular matrix, we perform operations on above the principal diagonal. when a matrix is converted into a lower triangular, the data that is present above the principal diagonal is zero in every entry. Some of the types of lower triangular matrices are:

  1. Lower triangular matrix
  2. Strictly lower triangular matrix
  3. Unit lower traingular matrix

Lower triangular matrix

A lower traingular matrix s a square matrix, whose elements are above the principal diagonal are zero. The syntax for lower traingular matrix is

upper.tri(matrix)

In this example, we created 3*3 matrix and converted it as lower traingular matrix.

R
#creating a matrix
mat=matrix(c(11:19),ncol=3)
print(mat)

print("The lower traingular matrix")
mat[upper.tri(mat)]=0
print(mat)