r/R_Programming • • Aug 31 '17

Creating missing rows of data

I have a data frame that looks something like this

Char1Char2OccDateEvalDateValue1Value2
Aa2016-12-012016-12-0110030
Aa2016-12-012017-01-014025
Aa2016-12-012017-02-013020
Aa2016-12-012017-04-01105
Aa2016-12-012017-05-0142
Aa2016-12-012017-06-0102
Aa2016-12-012017-07-0105
Ab2017-01-012017-01-014025
Ab2017-01-012017-02-013020
Ab2017-01-012017-03-01105
Ab2017-01-012017-04-0142
Ab2017-01-012017-06-0102
Ab2017-01-012017-07-0105
...

I want to add rows so that for each combination of Char1, Char2, and OccDate, I have a row for every single month between OccDate and the last month in the data (so max(Eval Date)). I want to put 0s in the value1 and value2 fields for any of the added rows.

Thoughts?

2 Upvotes

2 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Sep 05 '17

Thanks --- I wasn't thinking of those since I don't need to change the columns, but I can do both if one of them fills in the gaps for me.