当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 lower.tri()用法及代码示例


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

用法: lower.tri(x, diag)

参数:
x:矩阵对象
diag:包含对角线的布尔值

范例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

相关用法


注:本文由纯净天空筛选整理自nidhi_biet大神的英文原创作品 Return a Matrix with Lower Triangle as TRUE values in R Programming – lower.tri() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。