matrixIndex: Convert matrix element index to row/column coordinate or...

View source: R/matrixIndex.R

matrixIndexR Documentation

Convert matrix element index to row/column coordinate or vice-versa

Description

Convert matrix element index to row/column coordinate or vice-versa

Usage

matrixIndex(idx = NULL, coord = NULL, dim.mat = NULL)

Arguments

idx

numeric. Index of a matrix element

coord

numeric vector or matrix. Coordinate of an index (row,col)

dim.mat

numeric vector. Dimensions of matrix (rows, ncols)

Value

either a vector (indices) or matrix (coordinate) element

Examples

M <- matrix(1:20, 4,5)
M
matrixIndex(idx = 15, dim.mat = dim(M))
matrixIndex(coord = c(3,4), dim.mat = dim(M))
matrixIndex(coord = matrix(c(3,4,4,5), ncol=2, byrow=TRUE), 
  dim.mat = dim(M))



marchtaylor/sinkr documentation built on July 4, 2022, 5:48 p.m.