symIndices {kergp} | R Documentation |
Vector of Indices Useful for Symmetric or Anti-Symmetric Matrices.
Description
Vector of indices useful for symmetric or anti-symmetric matrices
Usage
symIndices(n, diag = FALSE)
Arguments
n |
Size of a square matrix. |
diag |
Logical. When |
Details
This function is intended to provide computations which are faster than
lower.tri
and upper.tri
.
Value
A list containing the following integer vectors, each with length
(n - 1) n / 2
.
i , j |
Row and column indices for the lower triangle to be used in a two-index style. |
kL |
Indices for the
lower triangle, to be used in single-index style. The elements are
picked in column order. So if |
kU |
Indices
for the upper triangle, to be used in a single-index style. The
elements are picked in row order. So if |
Examples
n <- rpois(1, lambda = 10)
L <- symIndices(n)
X <- matrix(1L:(n * n), nrow = n)
max(abs(X[lower.tri(X, diag = FALSE)] - L$kL))
max(abs(t(X)[lower.tri(X, diag = FALSE)] - L$kU))
cbind(row = L$i, col = L$j)