tidyr::complete()
adds rows to a data.frame
for combinations of column values that are missing from the data. Example:
library(dply
There might be a better answer out there, but this works:
dt[CJ(person=unique(dt$person),
observation_id=unique(dt$observation_id)),
on=c('person','observation_id')]
Which gives:
person observation_id value
1: 1 1 1
2: 2 1 1
3: 1 2 NA
4: 2 2 1
Now, if you would like to be able to fill with any value (and not NA
), I would suggest to wait for the corresponding feature to be finished or contribute to it :)