symIndices: Vector of Indices Useful for Symmetric or Anti-Symmetric...

Description Usage Arguments Details Value Examples

View source: R/miscUtils.R

Description

Vector of indices useful for symmetric or anti-symmetric matrices

Usage

1

Arguments

n

Size of a square matrix.

diag

Logical. When FALSE the diagonal is omitted in the lower and upper triangles.

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 X is a square matrix with size n, then X[kL] is the vector containing the elements of the lower triangle of X taken in column order.

kU

Indices for the upper triangle, to be used in a single-index style. The elements are picked in row order. So if X is a square matrix with size n, then X[kU] is the vector containing the elements of the upper triangle of X taken in row order.

Examples

1
2
3
4
5
6
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)

kergp documentation built on March 18, 2021, 5:06 p.m.