Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
r
communitycreator

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

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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")
Implementing the lower.tri() function

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.

RELATED TAGS

function
r
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring