當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。