I frequently do
DT[CJ(colA = colA, colB = colB, unique=TRUE), on=c("colA","colB")]
# to complete missing levels
# or
DT[, CJ(colA = colA, colB = colB, unique=TRUE)][!DT, on=c("colA","colB")]
# to identify missing levels
# http://stackoverflow.com/a/36065607/1191259
It would be nice if I could get away with writing colA and colB fewer times. The FR here is for
CJ(colA, colB, unique=TRUE, names=TRUE)
to infer the names colA and colB, perhaps using whatever method is used by data.frame() and data.table() (make.names?).
(The name repetition could be reduced further if on=.Icols were a thing, I suppose, but I'll leave that for a separate FR.)
SO posts to update...
I frequently do
It would be nice if I could get away with writing
colAandcolBfewer times. The FR here is forto infer the names
colAandcolB, perhaps using whatever method is used by data.frame() and data.table() (make.names?).(The name repetition could be reduced further if
on=.Icolswere a thing, I suppose, but I'll leave that for a separate FR.)SO posts to update...