我有一个看起来像这样的 data.frame
> head(df)
Memory Memory Memory Memory Memory Naive Naive
10472501 6.075714 5.898929 6.644946 6.023901 6.332126 8.087944 7.520194
10509163 6.168941 6.495393 5.951124 6.052527 6.404401 7.152890 8.335509
10496091 10.125575 9.966211 10.075613 10.310952 10.090649 11.803949 11.274480
10427035 6.644921 6.658567 6.569745 6.499243 6.990852 8.010784 7.798154
10503695 8.379494 8.153917 8.246484 8.390747 8.346748 9.540236 9.091740
10451763 10.986717 11.233819 10.643245 10.230697 10.541396 12.248487 11.823138
我想找到Memory
列的平均值和列的平均值Naive
。该aggregate
函数聚合行。这data.frame
可能有大量的行,因此转置然后aggregate
按colnames
原件应用data.frame
让我觉得很糟糕,而且通常很烦人:
> head(t(aggregate(t(df),list(colnames(df)), mean)))
[,1] [,2]
Group.1 "Memory" "Naive"
10472501 "6.195123" "8.125439"
10509163 "6.214477" "7.733625"
10496091 "10.11380" "11.55348"
10427035 "6.672665" "8.266854"
10503695 "8.303478" "9.340436"
我错过了什么明显的东西?