a = data.table(id = c(1L, 1L, 2L, 3L, NA_integer_), t = c(1L, 2L, 1L, 2L, NA_integer_), x = 11:15)
b = data.table(id = 1:2, y = c(11L, 15L))
# > a
# id t x
# 1: 1 1 11
# 2: 1 2 12
# 3: 2 1 13
# 4: 3 2 14
# 5: NA NA 15
# > b
# id y
# 1: 1 11
# 2: 2 15
a[b, on=.(id), sum(x), by = .(id)]
# > a[b, on=.(id), sum(x), by = .(id)]
# id V1
# 1: 1 23
# 2: 1 13
Why does the above query not return id = 2, V1 = 13 in the second row? I get what I would expect using by=.EACHI
though:
a[b, on=.(id), sum(x), by = .EACHI]
# > a[b, on=.(id), sum(x), by = .EACHI]
# id V1
# 1: 1 23
# 2: 2 13