triMatInd: Triangular matrix indices

View source: R/triMatInd.R

triMatIndR Documentation

Triangular matrix indices

Description

This function outputs the indices of one triangle (the lower one by default) of an input square matrix. It is used by simMat and, for large matrices, makes it faster than e.g. with lower.tri or upper.tri.

Usage

triMatInd(mat, lower = TRUE, list = FALSE)

Arguments

mat

a square matrix.

lower

logical indicating whether the indices should correspond to the lower triangle. The default is TRUE; FALSE produces the upper triangle indices.

list

logical indicating whether the results should be output as a list instead of a matrix. The default is FALSE.

Value

The indices (row, column) of the elements of the matrix that belong to the requested triangle.

Author(s)

A. Marcia Barbosa

References

http://stackoverflow.com/questions/20898684/how-to-efficiently-generate-lower-triangle-indices-of-a-symmetric-matrix

See Also

lower.tri, upper.tri

Examples

mat <- matrix(nrow = 4, ncol = 4)
mat
triMatInd(mat)
triMatInd(mat, list = TRUE)

fuzzySim documentation built on Oct. 31, 2022, 1:07 a.m.