I have a following line of code which replaces a value in a variable (var2
) based on a value in other variable (var1
)
df$var2[df$var1 > 0] <- NA
However I would like to extend this and replace variables (e.g var5
) in the data frame based on values in multiple other variables (var1
, var2
, var3
, var4
) which are coded in specific columns 13:16.
I tried
df$var5[df[c(13:16)] > 0] <- NA
which would not work correctly and I would like to know why and how to optimally amend the code.