lets say we have the following.:
time=c(20060200,20060200,20060200,20060200,20060200,20060300,20060400,20060400,20060400)
bucket=c(1,1,2,2,1,3,3,3,1)
rate=c(0.05,0.04,0.04,0.05,0.06,0.01,0.07,0.08,0.03)
time bucket rate
1: 20060200 1 0.05
2: 20060200 1 0.04
3: 20060200 2 0.04
4: 20060200 2 0.05
5: 20060200 1 0.06
6: 20060300 3 0.01
7: 20060400 3 0.07
8: 20060400 3 0.08
9: 20060400 1 0.03
i know how to aggregate the rate to time or bucket by something like this
test=data.table(time,bucket,rate)
b=test[,list(x=sum(rate)),by=bucket]
my question is how to aggregate to the bucket, while keeping the time intact.
so what i want is something like this:
20060200 1 0.15
20060200 2 0.09
20060200 3 0
20060300 1 0
20060300 2 0
20060300 3 0.01
20060400 1 0.03
20060400 2 0
20060400 3 0.15
hope this is clear, thanks