stm_triu()
returns the upper triangular part of a matrix, optionally
with a specified diagonal offset.
Arguments
- mat
A numeric matrix.
- k
An integer indicating the diagonal to be used. Default is 0
,
which returns the upper triangular part including the main diagonal.
Value
A matrix containing the upper triangular part of mat
,
with the specified diagonal offset.
Details
This function calls stm_tri_lower_upper()
to extract the upper
triangular part of the matrix.
Examples
A <- matrix(1:16, nrow = 4, byrow = TRUE)
print(A)
#> [,1] [,2] [,3] [,4]
#> [1,] 1 2 3 4
#> [2,] 5 6 7 8
#> [3,] 9 10 11 12
#> [4,] 13 14 15 16
stm_triu(A)
#> [,1] [,2] [,3] [,4]
#> [1,] 1 2 3 4
#> [2,] 0 6 7 8
#> [3,] 0 0 11 12
#> [4,] 0 0 0 16