Assuming x
is pre-initialized to be all ones, and df
is the data frame that contains a
, b
, and c
, then a simple solution is:
x[with(df, a + b + c == 0)] <- 0
Here we generate an index vector that contains TRUE
whenever the desired condition is met (a + b + c == 0
), and then use that to replace those values with zero in x
. With the data frame generated by @Shambho, we get:
[1] 1 1 0 1 1 0 1 1 1 1