TriIndex: Get the row and column indices of upper and lower trianges of...

Description Usage Arguments Value Note Author(s) References Examples

View source: R/TriIndex.R

Description

Given the number of rows in a symmetric matrix, calculate the row and column indices of the upper or lower triangles.

Usage

1
TriIndex(Nrow, which = "lower")

Arguments

Nrow

The number of rows

which

Specify which = "lower" or which = "upper". Defaults to "lower".

Value

A two-column matrix.

Note

A straightforward way to do this is to use which(lower.tri(YourMatrix), arr.ind = TRUE), however, this can be quite slow as the number of rows increases.

Author(s)

Ananda Mahto

References

http://stackoverflow.com/a/20899060/1270695

Examples

1
2
3
4
5
TriIndex(4)
TriIndex(4, "upper")

m <- matrix(0, nrow = 4, ncol = 4)
which(lower.tri(m), arr.ind = TRUE)

mrdwab/SOfun documentation built on June 20, 2020, 6:15 p.m.