So my question relates to the following case:
Suppose I have a numeric matrix mat
which has 10 rows and 10 columns.
And I create a second matrix mat_filter
which is supposed to specify the elements that should be modified.Lets say i want to modify elements in the positions: (1,1) (6,5) (10,3)
Like so:
mat <- matrix(7,10,10)
mat_filter <- cbind(c(1,6,10),
c(1,5,3))
Now i try to modify mat
:
mat[mat_filter] <- mat[mat_filter] + 1
my question is, what exactly is getting copied by R when I try to modify the specified matrix elements like this? Is the entire matrix getting copied? In general what I want to understand is where redundancies occur in these types of modifications, I know that using lists its possible to modify objects in place, also with individual vectors, but what about matrices? When I use the i,j indexing of the matrix, is that any different than using the single integer indexing of the matrix?