Logical Matrix Giving the Lower or Upper Triangle

DESCRIPTION:

Returns a matrix of logicals the same size as x which is TRUE in the lower triangle or upper triangle.

USAGE:

lower.tri(x, diag=F)
upper.tri(x, diag=F)

REQUIRED ARGUMENTS:

x
a matrix.

OPTIONAL ARGUMENTS:

diag
logical flag: if TRUE, then include the diagonal in the lower (or upper) triangle (that is, make the diagonal elements of the result TRUE).

VALUE:

matrix of the same dimension as x which for lower.tri is FALSE above the diagonal and TRUE below the diagonal. For upper.tri the matrix is FALSE below the diagonal and TRUE above the diagonal.

SEE ALSO:

, .

EXAMPLES:

lower.tri(freeny.x) 
upper.tri(freeny.x, T) 

# A correlation matrix with 0.5 on all off-diagonals:
corr <- diag(5)
corr[lower.tri(corr)] <- 0.5
corr[upper.tri(corr)] <- 0.5
corr