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

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

     [, 1]  [, 2]  [, 3]
[1, ] TRUE FALSE FALSE
[2, ] TRUE  TRUE FALSE
[3, ] TRUE  TRUE  TRUE
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.