My apologies in advance for any non-compliance with the rules of posting a question. The data table below is a sample of what I want to convert into a time series.
> Materials
MaterialID Date Quantity
1 2011-01-04 13
1 2011-01-04 5
2 2011-01-07 9
3 2011-01-09 3
3 2011-01-11 10
It consists of transaction entries for several Material items between 2011- 2014.The date range for the entire data set is from 4th Jan, 2011 - 31st Dec 2014. I want to create a transaction entry for each material within this period while accounting for the missing dates by setting the Quantity variable to zero for the missing dates. To put it another way the outcome I desire is that there will be an entry for each Material in the data set for every date between 4th Jan, 2011 - 31st Dec 2014 as shown below:
Date MaterialID_1 MaterialID_2 MaterialID_3
2011-01-04 13 0 0
2011-01-04 5 0 0
2011-01-05 0 0 0
2011-01-06 0 0 0
2011-01-07 0 9 0
2011-01-08 0 0 0
2011-01-09 0 0 3
2011-01-10 0 0 10
2011-01-11 0 0 0
. . . .
. . . .
. . . .
2014-12-31 0 0 0
I have tried some of the methods I have seen in the forum such as Add months of zero demand to zoo time series, but because I have duplicated dates I get the error, "index entries in ‘order.by’ are not unique". I'd appreciate any advise or help I can get with this.
After getting the data into this format, my intention is to reshape the data set to do batch forecasting. Thanks.
See dput code below:
dput(Data)
structure(list(MaterialID = c(1L, 1L, 2L, 3L, 1L), Date = c("2011-01-04",
"2011-01-04", "2011-01-07", "2011-01-09", "2011-01-11"), Quantity = c(13L,
5L, 9L, 3L, 10L)), .Names = c("MaterialID", "Date", "Quantity"
), class = "data.frame", row.names = c(NA, -5L))