title: Add missing values in time series efficiently
body: <p>I have 500 datasets (panel data). In each I have a time series (week) across different shops (store). Within each shop, I would need to add missing time series observations.</p>
  
  <p>A sample of my data would be:</p>
  
  <pre><code>store   week           value
  1           1          50
  1           3          52
  1           4          10
  2           1          4
  2           4          84
  2           5          2
  </code></pre>
  
  <p>which I would like to look like:</p>
  
  <pre><code>store   week        value
  1           1       50
  1           2       0
  1           3       52
  1           4       10
  2           1       4
  2           2       0
  2           3       0
  2           4       84
  2           5       2
  </code></pre>
  
  <p>I currently use the following code (which works, but takes very very long on my data):</p>
  
  <pre><code>  stores&lt;-unique(mydata$store)
  
    for (i in 1:length(stores)){ 
    mydata &lt;- merge(
      expand.grid(week=min(mydata$week):max(mydata$week)),
      mydata, all=TRUE)
    mydata[is.na(mydata)] &lt;- 0
    }
  </code></pre>
  
  <p>Are there better and more efficient ways to do so?</p>