我有一个数据表格,A
如下:
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
我想使用它来遮蔽另一个数据表,其sigma值低于阈值,比如2。假设我的第二个数据表是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
所以,我想要像
B[A<2]
这样的东西,但显然这不起作用,否则我就不会在这里了。有什么建议吗?
预期输出:
输出
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
目标是找到对应于数据表A中sigma小于2的位置。
i1 <- setDT(A)[, Reduce('&', lapply(.SD,
<, 2)), .SDcols = 3:5]; B[i1]
。 - akrun