我想知道是否有一种有效的方法来通过另一个数据表中定义的多个条件筛选数据表。在这种情况下,有两个数据表:
# the filter data.table defines the condition
dt_filter<-data.table(A=c(1,2),B=c(8,7))
# dt1 the data.table to be filtered
dt1<-data.table(A=rep(c(1,2),5),B=c(8,4,3,1,1,5,9,7,1,1),C=c(rep(1,5),rep(2,5)))
ls_tmp<-lapply (1:nrow(dt_filter),function(i){
# exclude the record with the A&B defined the filter
dt1_add<-dt1[A==dt_filter[[i,1]]&B!=dt_filter[[i,2]]]
})
result<- rbindlist(ls_tmp)
看起来我的示例不够高效,因为使用了lapply循环。我不确定如何通过其他方式重新编写它。
A,B,C
。B!= dt_filter [....
这里的不等于是打错了吗? - Vlo