at: Set or get matrix value at index vector

Description Usage Arguments Value Examples

View source: R/at.R

Description

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

Usage

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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)

matricks documentation built on March 26, 2020, 6:22 p.m.