at {matricks} | R Documentation |
Set or get matrix value at index vector
Description
This function allows to access matrix values by passing indices as vector
Usage
at(mat, idx)
at(mat, idx) <- value
Arguments
mat |
matrix |
idx |
two-element integer vector |
value |
a value to be assign at index |
Value
'at' function: value from matrix at index idx
Examples
mat <- matrix(0, 3, 3)
idx <- c(1, 2)
# Typically, given matrix and row-column indices as two-element vector, we should do it like this:
mat[idx[1], idx[2]]
mat[idx[1], idx[2]] <- 8
# Using `at`, we can do it simplier!
at(mat, idx)
at(mat, idx) <- 7
mat
at(mat, idx)
[Package matricks version 0.8.2 Index]