📜  在 R 编程中返回具有下三角形作为 TRUE 值的矩阵 – lower.tri()函数

📅  最后修改于: 2022-05-13 01:54:19.791000             🧑  作者: Mango

在 R 编程中返回具有下三角形作为 TRUE 值的矩阵 – lower.tri()函数

R 语言中的lower.tri()函数用于返回下三角形为 TRUE 的逻辑值矩阵。

示例 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)

输出:

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

示例 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)

输出:

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