What is the lower.tri() function in R?
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 Objectmymatrix <- matrix ( rep(12, 3*5),nrow = 5)mymatrix# implementing the lower.tri() functionlower.tri(mymatrix)# including a diagonallower.tri(mymatrix, diag="TRUE")
Explanation
- Line 2: We create a matrix,
mymatrix, using thematrix()function. - Line 4: We print the matrix
mymatrix. - Line 7: We call the
lower.tri()function and passedmymatrixas its argument. We print the result to the console. - Line 10: We call the
lower.tri()function and pass themymatrixas its argument. We also include the diagonal by setting thediagasTRUE. We print the result to the console.