这是一个人为的例子(因此缺乏输出),但它足够简单(希望)来证明我的问题。我想计算按“Country”和“FavoriteColor”分组的每个子组的 mean() Income。
#For a single subgroup
mean(dat[J("Blue","Nigeria")]$Income) #dat is a data.table object
#For all the subgroups...in the output I obviously
#see the mean() for Blue/Nigeria subgroup. So far so good.
dat[,mean(Income),by=list((FavoriteColor,Country)]
但是现在,我想要子组的所有收入汇总()统计数据,而不仅仅是平均值()。所以我干脆...
#For a single subgroup
summary(dat[J("Blue","Nigeria")]$Income)
#For all the subgroups... but this doesn't do what I expect.
#It seems to computing something else entirely; I think
#its calling summary() on each row
dat[,summary(Income),by=list(FavoriteColor,Country)]
我究竟做错了什么?