# 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)
Run the code above in your browser using DataLab