I have data
dat <- data.table(id=c(1,1,1,2,2,2,3,3), week=c(1,2,3,1,2,3,1,3), val=c(1,2,3,5,6,7,9,10))
> dat
id week val
1: 1 1 1
2: 1 2 2
3: 1 3 3
4: 2 1 5
5: 2 2 6
6: 2 3 7
7: 3 1 9
8: 3 3 10
where for id=3
a value is missing for week 2. I want to fill these gaps with val=0
and wonder how this can be done.
I have tried to get weeks <- 1:3
and join this with dat
but it did not help.