最佳答案
I cannot seem to find any documentation on what exactly .EACHI
does in data.table
. I see a brief mention of it in the documentation:
Aggregation for a subset of known groups is particularly efficient when passing those groups in i and setting
by=.EACHI
. Wheni
is a data.table,DT[i,j,by=.EACHI]
evaluatesj
for the groups ofDT
that each row ini
joins to. We call this grouping by each i.
But what does "groups" in the context of DT
mean? Is a group determined by the key that is set on DT
? Is the group every distinct row that uses all the columns as the key? I fully understand how to run something like DT[i,j,by=my_grouping_variable]
but am confused as to how .EACHI
would work. Could someone explain please?