Skip to content
Related Articles

Related Articles

Improve Article

Return a Matrix with Lower Triangle as TRUE values in R Programming – lower.tri() Function

  • Last Updated : 16 Jun, 2020

lower.tri() function in R Language is used to return a matrix of logical values with lower triangle as TRUE.

Syntax: lower.tri(x, diag)

Parameters:
x: Matrix object
diag: Boolean value to include diagonal

Example 1:




# R program to print the 
# lower triangle of a matrix
  
# Creating a matrix
mat <- matrix(c(1:9), 3, 3, byrow = T)
  
# Calling lower.tri() Function
# Excluding diagonal elements
lower.tri(mat, diag = F)

Output:

      [, 1]  [, 2]  [, 3]
[1, ] FALSE FALSE FALSE
[2, ]  TRUE FALSE FALSE
[3, ]  TRUE  TRUE FALSE

Example 2:




# R program to print the 
# lower triangle of a matrix
  
# Creating a matrix
mat <- matrix(c(1:9), 3, 3, byrow = T)
  
# Calling lower.tri() Function
# including diagonal elements
lower.tri(mat, diag = T)

Output:

     [, 1]  [, 2]  [, 3]
[1, ] TRUE FALSE FALSE
[2, ] TRUE  TRUE FALSE
[3, ] TRUE  TRUE  TRUE
My Personal Notes arrow_drop_up
Recommended Articles
Page :