示例数据:
tmp_dt1<- data.table(grp = c(1,2), time = c(0.2, 0.6, 0.4, 0.8, 0.25, 0.65))
tmp_dt2 <- data.table(grp = c(1,2), time_from = c(0.1, 0.5))
> tmp_dt1
grp time
1: 1 0.20
2: 2 0.60
3: 1 0.40
4: 2 0.80
5: 1 0.25
6: 2 0.65
> tmp_dt2
grp time_from
1: 1 0.1
2: 2 0.5
我会执行以下操作,尝试在time_from
和time_from + 0.2
之间找到每个组中的所有内容,但它会出错:
> tmp_dt1[tmp_dt2, .(grp, time = x.time, time_from, time_to), on = .(grp, time >= time_from, time <= time_from + 0.2)]
Error in `[.data.table`(tmp_dt1, tmp_dt2, .(grp, time = x.time, time_from, :
Column(s) [time_from + 0.2] not found in i
即。它不喜欢在非equi连接规范中创建的边界。有没有办法以交互方式编写这些边界,而无需创建中间变量tmp_dt2$time_to <- tmp_dt2$time_from + 0.2
?