You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Example from https://stackoverflow.com/q/25956178
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]
toj
when.N == 0L
), eg likenomatch = integer(0)
, though that's kind of esoteric notation.More examples, I think: https://stackoverflow.com/q/57526710
The text was updated successfully, but these errors were encountered: