I have a numeric matrix as follows
1 2 3 4 5
1 4 6 1 4
2 4 1 6 8
1 7 3 6 7
1 4 5 6 2
I have a vector c(2,4,2,6,8)
For each row I want to take the corresponding value in the vector and make a new matrix where all the values in the row greater than the vector value goes to 0.
The output should look like
1 2 0 0 0 # greater than 2 is changed to 0
1 4 0 1 4 # greater than 4 changed to 0
2 0 1 0 0 # greater than 2 changed to 0
1 0 3 6 0 # greater than 6 changed to 0
1 4 5 6 2 # greater than 8 changed to 0
Is there a way to do this without actually coding through a loop?