I'd like to build up on a question I asked earlier (Adding row for missing value in data.table). Actualy I don't need to add so many zero, I only need the first missing one to be 0.
So this time I would like to insert a 0 only if the last entry for the same ('ida', 'idb') is not already 0. We suppose there is no 0 in the original data.table.
So an example would be :
ida idb value date
A 3 26600 2004-12-31
A 3 19600 2005-03-31
A 3 18200 2005-06-30
A 4 9560 2004-12-31
B 1 2600 2004-12-31
B 1 100 2005-03-31
B 1 8200 2005-06-30
B 1 9560 2007-12-31
B 9 1423 2004-12-31
B 9 1235 2005-06-30
C 2 8700 2005-12-31
Gives :
ida idb value date
A 3 26600 2004-12-31
A 3 19600 2005-03-31
A 3 18200 2005-06-30
A 4 9560 2004-12-31
A 4 0 2005-03-31
B 1 2600 2004-12-31
B 1 100 2005-03-31
B 1 8200 2005-06-30
B 1 9560 2007-12-31
B 9 1423 2004-12-31
B 0 0 2005-03-31
B 9 1235 2005-06-30
B 0 0 2007-12-31
C 2 8700 2005-12-31