kIndex | R Documentation |
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.
kIndex(i, j, nr, nc, byRows = FALSE)
ijIndex(k, nr, nc, byRows = FALSE)
kColToRow(k, nr, nc)
kRowToCol(k, nr, nc)
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
|
Depending on the function:
kIndex
: a vector of length nr * nc
with the linear
indexes for A
.
ijIndex
: a matrix of dimension c(length(k), 2)
giving
cbind(i, j)
.
kColToRow
and kRowToCol
: a vector of length
nr * nc
giving the permuting indexes to change the ordering of the
linear indexes.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.