I have a matrix call res initially like the following:
[,1] [,2]
[1,] 0 0
[2,] 0 0
[3,] 0 0
[4,] 0 0
[5,] 0 0
[6,] 0 0
[7,] 0 0
[8,] 0 0
[9,] 0 0
[10,] 0 0
I have a matrix of indexes (indexes) like the following:
[,1] [,2]
[1,] 2 3
[2,] 7 9
I want the resulting res matrix to be like the following:
[,1] [,2]
[1,] 0 0
[2,] 1 1
[3,] 1 1
[4,] 0 0
[5,] 0 0
[6,] 0 0
[7,] 1 1
[8,] 1 1
[9,] 1 1
[10,] 0 0
I have a big matrix, it takes a long time to loop through the indexes matrix. Please let me know if there is a better approach to do this. I am hoping to do something like mat[indexes,] <- 1. However, this does not work I wanted.