Skip to contents

Extract the lower triangular part of a matrix.

Usage

tril(x, k = 0, diag = TRUE)

Arguments

x

A matrix.

k

The sub-diagonal at and below which the matrix is filled. k = 0 is the main diagonal, while k < 0 is below it, and k > 0 is above. The default is 0.

diag

Logical indicating whether to include the diagonal. Default is TRUE.

Examples

tril(ones(5, 5))
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    0    0    0    0
#> [2,]    1    1    0    0    0
#> [3,]    1    1    1    0    0
#> [4,]    1    1    1    1    0
#> [5,]    1    1    1    1    1
tril(ones(5, 5), diag = TRUE)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    0    0    0    0
#> [2,]    1    1    0    0    0
#> [3,]    1    1    1    0    0
#> [4,]    1    1    1    1    0
#> [5,]    1    1    1    1    1