Chainable functional alias for x[i, j] <- value
. It provides flexibility
for setting values using either one or two indices. Note that if you only
want to modify columns (j
), the argument along with the value
must be
named. Alternatively use setCol. if neither i
nor j
is provided, an
error is thrown.
Examples
mat <- matrix(1:9, nrow = 3)
setIndex(mat, 1, 2, 10) # Set value at position (1, 2)
#> [,1] [,2] [,3]
#> [1,] 1 10 7
#> [2,] 2 5 8
#> [3,] 3 6 9
setIndex(mat, 1, value = 20) # Set entire first row to 20
#> [,1] [,2] [,3]
#> [1,] 20 20 20
#> [2,] 2 5 8
#> [3,] 3 6 9
setIndex(mat, j = 3, value = 30) # Set entire third column to 30
#> [,1] [,2] [,3]
#> [1,] 1 4 30
#> [2,] 2 5 30
#> [3,] 3 6 30