I\'m looking for an elegant way to iterate over the key of data.table, drop the rows that have that key, then take a summary over the remaining rows. For example:
I think this does it, using more traditional data.table code:
setkey(mydt,cat)
mydt[, list(means=mean(mydt[!.BY,vals])), by=cat]
# or without needing to key first
mydt[, list(means=mean(mydt[cat != .BY,vals])), by=cat]
# cat means
#1: a 5.0
#2: b 4.2
#3: c 2.5