This function allows to access matrix values by passing indices as vector
at(mat, idx) at(mat, idx) <- value
mat | matrix |
---|---|
idx | two-element integer vector |
value | a value to be assign at index |
`at` function: value from matrix at index idx
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] 0mat[idx[1], idx[2]] <- 8 # Using `at`, we can do it simplier! at(mat, idx)#> [1] 8at(mat, idx) <- 7 mat#> [,1] [,2] [,3] #> [1,] 0 7 0 #> [2,] 0 0 0 #> [3,] 0 0 0at(mat, idx)#> [1] 7