I have two matrices
A
2 1 0
0 1 6
1 0 0
B
1 1 3
4 2 8
2 0 1
I want to find out the elements comparing A and B satisfying the following criteria:
if A[i,j] =0 and B[i,j]>0
So my result matrix should be
C
0 0 3
4 0 0
0 0 1
What is a proper way to do this except for a for loop?
Regular logical and arithmetic operators act element wise on matrices in R. Only the
%*%and kronecker operators do matrix multiplication. Furthermore you can index matrixes using the “[” and “[<-” functions: