pkern_vec2mat | R Documentation |
Inverts the function pkern_mat2vec
, returning matrix row and column numbers i, j,
given the column-vectorized index k
and matrix dimensions gdim
.
pkern_vec2mat(k, gdim, out = "matrix")
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' |
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))
a two column matrix of integers (row and column numbers) with length(k)
rows
# 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
pkern_vec2mat(2, gdim)
pkern_vec2mat(c(2, 10, 5), gdim)
pkern_vec2mat(c(2, 10, 5), gdim, out='list')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.