lower.tri {base} | R Documentation |
Lower and Upper Triangular Part of a Matrix
Description
Returns a matrix of logicals the same size of a given matrix with
entries TRUE
in the lower or upper triangle.
Usage
lower.tri(x, diag = FALSE)
upper.tri(x, diag = FALSE)
Arguments
x |
a matrix. |
diag |
logical. Should the diagonal be included? |
See Also
diag
,
matrix
.
Examples
m2 <- ma <- matrix(1:20, 4, 5)
m2[lower.tri(m2)] <- NA
m2
stopifnot(lower.tri(ma) == !upper.tri(ma, diag=TRUE))