tri | R Documentation |
Extract lower or upper triangular part of a matrix.
tril(M, k = 0)
triu(M, k = 0)
M |
numeric matrix. |
k |
integer, indicating a secondary diagonal. |
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.
Matrix the same size as the input matrix.
For k==0
it is simply an application of the R functions
lower.tri
resp. upper.tri
.
Diag
tril(ones(4,4), +1)
# 1 1 0 0
# 1 1 1 0
# 1 1 1 1
# 1 1 1 1
triu(ones(4,4), -1)
# 1 1 1 1
# 1 1 1 1
# 0 1 1 1
# 0 0 1 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.