I have data with various columns and I need to use few conditional statements on the columns. I am able to write following code successfully for conditions to be applied on two columns i.e., AB and MN.
if ("ABq" %in% colnames(x)) {
x[ABq != 0, AB := NA]
x[AB < 10 | DIF > 100, AB := NA]
}
if ("MNq" %in% colnames(x)) {
x[MNq != 0, MN := NA]
x[MN < 25 | MN > 150, MN := NA]
}
I have another column i.e., XY. I need to put a condition on XY that XY should have valid values only for the rows which have valid values for AB as well as MN, else it should be NA. (valid values mean with in the defined range). How can I write it in R?