-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
joinsUse label:"non-equi joins" for rolling, overlapping, and non-equi joinsUse label:"non-equi joins" for rolling, overlapping, and non-equi joins
Description
Example from https://stackoverflow.com/q/25956178
library(data.table)
DT = data.table(
x = c("A", "A", "A", "B", "B", "B"),
y = c("i", "ii", "ii", "i", "i", "i"),
z = 1:6
)
# .N correctly displays 0 for unmatched group
DT[CJ(x, y, unique=TRUE), on=.(x, y), .N, by=.EACHI]
# x y N
# 1: A i 1
# 2: A ii 2
# 3: B i 3
# 4: B ii 0
# .I correctly (?) displays 0 for unmatched group
DT[CJ(x, y, unique=TRUE), on=.(x, y), .I, by=.EACHI]
# x y I
# 1: A i 1
# 2: A ii 2
# 3: A ii 3
# 4: B i 4
# 5: B i 5
# 6: B i 6
# 7: B ii 0
# z incorrectly is NA for unmatched group
DT[CJ(x, y, unique=TRUE), on=.(x, y), sum(z), by=.EACHI]
# x y V1
# 1: A i 1
# 2: A ii 5
# 3: B i 15
# 4: B ii NA
Intuitively, I expect the latter to be 0, with sum(z) operating on .SD[0]$z for the unmatched group. Re #857, maybe this can also be included as an option (passing .SD[0] to j when .N == 0L), eg like nomatch = integer(0), though that's kind of esoteric notation.
More examples, I think: https://stackoverflow.com/q/57526710
jangorecki and brodieG
Metadata
Metadata
Assignees
Labels
joinsUse label:"non-equi joins" for rolling, overlapping, and non-equi joinsUse label:"non-equi joins" for rolling, overlapping, and non-equi joins