sk_vec2mat: Invert column-vectorization indices

View source: R/sk_index.R

sk_vec2matR Documentation

Invert column-vectorization indices

Description

Inverts the function sk_mat2vec, returning matrix row and column numbers i, j, given the column-vectorized index k and matrix dimensions gdim.

Usage

sk_vec2mat(k, gdim, out = "matrix")

Arguments

k

a vector of positive integers, the vector indices to look up

gdim

integer (or vector with first element equal to) the number of rows in the matrix

out

either 'matrix' or 'list'

Details

Output indices are returned in a matrix with columns 'i', 'j' and rows in same order as the input k. When out='list' list of vectors 'i' and 'j' (with entries in the same order) is returned instead.

The entries of k can be any permutation with replacement from seq(prod(gdim))

Value

a two column matrix of integers (row and column numbers) with length(k) rows

See Also

Other indexing functions: sk_mat2vec(), sk_rescale(), sk_sub_find(), sk_sub_idx()

Examples


# show how elements are ordered in `base::matrix`
gdim = c(5, 6)
matrix_order = matrix(1:prod(gdim), gdim)
print(matrix_order)

# identify the row and column numbers for specific entry, or several
sk_vec2mat(2, gdim)
sk_vec2mat(c(2, 10, 5), gdim)
sk_vec2mat(c(2, 10, 5), gdim, out='list')


snapKrig documentation built on May 31, 2023, 6:34 p.m.