Row and column indices around the diagonal of a square matrix
Source:R/FUNCTIONS_MATRIX.R
off_diagonal_index.RdFor each diagonal position i of a length x length
matrix, returns the indices of the diagonal cell and of its two neighbours
in the same row: the cell to the right (just above the diagonal, column
i + 1) and the cell to the left (just below the diagonal, column
i - 1).
Value
A data frame (not a matrix) with length rows and four numeric
columns:
- x1
Row index
i.- x2
Column index of the diagonal cell (same as
x1).- x3
Column index of the cell to the right,
i + 1; in the last row this islength + 1, outside the matrix.- x4
Column index of the cell to the left,
i - 1; in the first row this is0, outside the matrix.