I have two tables both 4x4 dimension. I wold like to know how I can replace a cell in the first table with a 0 if there is a 0 in the corresponding cell of the bottom table (using an R command, I'm guessing an If statement or sub-setting). E.g the first row and column of the first table (-0.2) should be converted to zero based on the 0 value of the first row and column of the second table (-0.2)? Thanks
first table
-0.2, 0.5, 0.8, 0.01, 1, -0.4, 0.8, 0.5, 0.5, 0.3, -0.1, 0.8, -0.8, 0.5, 0.5, -0.02, (4x4)
second table
0, 0, 1.8, 0,
0, 2.7, 0, 0,
0, 0, 3.2, 0,
0, 0, 0, 0,
(4x4)
If your tables (matrices or data frames) are called tab1
and tab2
, you can use the following command:
tab1[!tab2] <- 0