kIndex {sdetorus} | R Documentation |
Utilities for conversion between row-column indexing and linear indexing of matrices
Description
Conversions between cbind(i, j)
and k
such that
A[i, j] == A[k]
for a matrix A
. Either column or row
ordering can be specified for the linear indexing, and also direct
conversions between both types.
Usage
kIndex(i, j, nr, nc, byRows = FALSE)
ijIndex(k, nr, nc, byRows = FALSE)
kColToRow(k, nr, nc)
kRowToCol(k, nr, nc)
Arguments
i |
row index. |
j |
column index. |
nr |
number of rows. |
nc |
number of columns. |
byRows |
whether to use row-ordering instead of the default column-ordering. |
k |
linear indexes for column-stacking or row-stacking ordering (if
|
Value
Depending on the function:
-
kIndex
: a vector of lengthnr * nc
with the linear indexes forA
. -
ijIndex
: a matrix of dimensionc(length(k), 2)
givingcbind(i, j)
. -
kColToRow
andkRowToCol
: a vector of lengthnr * nc
giving the permuting indexes to change the ordering of the linear indexes.
Examples
# Indexes of a 3 x 5 matrix
ij <- expand.grid(i = 1:3, j = 1:5)
kCols <- kIndex(i = ij[, 1], j = ij[, 2], nr = 3, nc = 5)
kRows <- kIndex(i = ij[, 1], j = ij[, 2], nr = 3, nc = 5, byRows = TRUE)
# Checks
ijIndex(kCols, nr = 3, nc = 5)
ij
ijIndex(kRows, nr = 3, nc = 5, byRows = TRUE)
ij
# Change column to row (and viceversa) ordering in the linear indexes
matrix(1:10, nr = 2, nc = 5)
kColToRow(1:10, nr = 2, nc = 5)
kRowToCol(kColToRow(1:10, nr = 2, nc = 5), nr = 2, nc = 5)
[Package sdetorus version 0.1.10 Index]