This function allows to access matrix values by passing indices as vector

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]]
#> [1] 0
mat[idx[1], idx[2]] <- 8 # Using `at`, we can do it simplier! at(mat, idx)
#> [1] 8
at(mat, idx) <- 7 mat
#> [,1] [,2] [,3] #> [1,] 0 7 0 #> [2,] 0 0 0 #> [3,] 0 0 0
at(mat, idx)
#> [1] 7