我已按照此example分区并绘制了我的数据。现在,有人建议我在图表中添加一个条形图,显示每个bin中包含的数据量。
如何总结每个bin的行中的值?
答案 0 :(得分:0)
我想我现在明白了:你想要所有适合bin的值的总和吗?
您可以使用tapply
:
n = 100
x = rnorm(n)
n.breaks = as.integer(sqrt(n))
bins = cut(x, breaks = n.breaks)
sums = tapply(x, bins, sum)
print(sums)
(-2.65,-2.17] (-2.17,-1.7] (-1.7,-1.23] (-1.23,-0.754] (-0.754,-0.281]
-7.5825100 -7.6457772 -5.6796399 -8.6823512 -12.8808658
(-0.281,0.193] (0.193,0.666] (0.666,1.14] (1.14,1.61] (1.61,2.09]
-0.8756864 8.1137694 7.5262578 4.1649094 10.8759823