> x <- data.table(a=1:10, b=rep(1:2, 5))
> x
a b
1: 1 1
2: 2 2
3: 3 1
4: 4 2
5: 5 1
6: 6 2
7: 7 1
8: 8 2
9: 9 1
10: 10 2
> x[,c:=mean(a), by=b]
> y <- x$c
> y
[1] 5 6 5 6 5 6 5 6 5 6
最終的に、私はy
ベクトルとして興味がc
あり、data.table
. y
オリジナルから取得する簡単な方法はありx
ますか?
ヒストグラム内の異なるグループに異なる重みを適用しようとすると、問題が発生します。
# here weight would be the same for all colour, but I wish they differ.
geom_freqpoly(aes(colour=group, weight=mean(y)), binwidth=1)