What is the lower.tri() function in R?

Overview

The lower.tri() function in R is used to return a matrix of logical values (TRUE and FALSE) that have the same size of the input matrix with lower triangle as TRUE.

Syntax

lower.tri(x, diag = FALSE)
Syntax for the lower.tri() function

Parameter values

The lower.tri() function takes the following parameter values:

  • x: This is the matrix object. It is a required parameter.
  • diag: This takes a logical value indicating whether the diagonal should be included or not. This is an optional parameter.

Example

# creating a matrix Object
mymatrix <- matrix ( rep(12, 3*5),
nrow = 5)
mymatrix
# implementing the lower.tri() function
lower.tri(mymatrix)
# including a diagonal
lower.tri(mymatrix, diag="TRUE")

Explanation

  • Line 2: We create a matrix, mymatrix, using the matrix() function.
  • Line 4: We print the matrix mymatrix.
  • Line 7: We call the lower.tri() function and passed mymatrix as its argument. We print the result to the console.
  • Line 10: We call the lower.tri() function and pass the mymatrix as its argument. We also include the diagonal by setting the diag as TRUE. We print the result to the console.