Extract lower or upper triangular part of a matrix.

Usage

tril(M, k = 0)
triu(M, k = 0)

Arguments

M

numeric matrix.

k

integer, indicating a secondary diagonal.

Value

Matrix the same size as the input matrix.

Details

tril
Returns the elements on and below the kth diagonal of X, where k = 0 is
the main diagonal, k > 0 is above the main diagonal, and k < 0 is below
the main diagonal.

triu
Returns the elements on and above the kth diagonal of X, where k = 0 is
the main diagonal, k > 0 is above the main diagonal, and k < 0 is below
the main diagonal.