Here is one approach.
nGroups <- length(unique(dt[,myGroup])) dt[, if(length(unique(myGroup))==nGroups) .BY else NULL, by="a"][[1]]
And with some explanatory comments.
## Mark down the number of groups in your data set nGroups <- length(unique(dt[,myGroup])) ## Then, use `by="a"` to examine in turn subsets formed by each value of "a". ## For subsets having the full complement of groups ## (ie those for which `length(unique(myGroup))==nGroups)`, ## return the value of "a" (stored in .BY). ## For the other subsets, return NULL. dt[, if(length(unique(myGroup))==nGroups) .BY else NULL, by="a"][[1]] # [1] 2
If this code and comments are not understood on their own, a quick look at the following may help. Basically, the approach described above simply searches and reports the value of a
for those groups that return x,y,z
in column V1
below.
dt[,list(list(unique(myGroup))), by="a"]
source share