Hi,
I've 2 matrix:
matrix1 = matrix(1, 10, 1)
matrix2 = matrix(seq(1,10,1),1,1)
matrix1 value will be updated based on matrix2. E.g. suppose in matrix2, only 2, 3, 4 position
has value and rest has 0, then matrix1 value will be updated to, say 2, for position 2,3,4.
So the new matrix looks like this:
matrix1 = matrix("1 2 2 2 1 1 1 1 1 1", 10, 1)
matrix2 = matrix("0 2 3 4 0 0 0 0 0 0", 10, 1)
I used the following code to update the matrix:
matrix2_1 = removeEmpty(target = matrix2, margin = "rows");
for(k in 1:nrow(matrix2_1 )){
matrix1 [as.scalar(matrix2_1 [k,]),] = 2
}
This code works, but I would like this calculation in matrix form. I tried it using "table"
function. But I'm yet to understand fully the use of "table". So unable to do it.
Can anyone please help me to solve the problem?
Thank you!
Arijit
