I have a data table, A like:
year location sigma_NN_1 sigma_NN_2 sigma_NN_3 2076 43.59375_-116.78125 1.4681173 1.664289 1.735974 2077 43.59375_-116.78125 1.3798515 1.550524 1.551269 2078 43.59375_-116.78125 0.7934367 1.064248 1.177981 2079 43.59375_-116.78125 1.8235574 1.991018 2.288402 2080 43.59375_-116.78125 2.5560329 2.578093 2.589334 And I want to use it to mask another data table where the value of sigmas are below a threshold, lets say 2. Lets say my second data table is B
year location location_NN_1 location_NN_2 location_NN_3 2076 43.59375_-116.78125 41.15625_-90.65625 41.21875_-90.65625 41.15625_-90.65625 2077 43.59375_-116.78125 43.34375_-78.15625 43.34375_-78.21875 43.28125_-78.15625 2078 43.59375_-116.78125 41.34375_-90.78125 41.21875_-90.65625 41.53125_-73.96875 2079 43.59375_-116.78125 43.53125_-116.78125 41.34375_-90.78125 41.71875_-74.15625 2080 43.59375_-116.78125 41.34375_-90.78125 41.96875_-86.21875 41.21875_-90.65625 So, I want to have something like B[A<2], but obviously this does not work, otherwise, I would not be here.
Any suggestions?
Expected output:
output
year location location_NN_1 location_NN_2 location_NN_3 2076 43.59375_-116.78125 41.15625_-90.65625 41.21875_-90.65625 41.15625_-90.65625 2077 43.59375_-116.78125 43.34375_-78.15625 43.34375_-78.21875 43.28125_-78.15625 2078 43.59375_-116.78125 41.34375_-90.78125 41.21875_-90.65625 41.53125_-73.96875 2079 43.59375_-116.78125 43.53125_-116.78125 41.34375_-90.78125 NA 2080 43.59375_-116.78125 NA NA NA The goal is to find locations whose corresponding sigma in data table A is less than 2.
i1 <- setDT(A)[, Reduce('&', lapply(.SD,<, 2)), .SDcols = 3:5]; B[i1]