title: Fastest way for filling-in missing dates for data.table
body: <p>I am loading a <code>data.table</code> from CSV file that has date, orders, amount etc. fields.</p>
  
  <p>The input file occasionally does not have data for all dates. For example, as shown below:</p>
  
  <pre><code>&gt; NADayWiseOrders
             date orders  amount guests
    1: 2013-01-01     50 2272.55    149
    2: 2013-01-02      3   64.04      4
    3: 2013-01-04      1   18.81      0
    4: 2013-01-05      2   77.62      0
    5: 2013-01-07      2   35.82      2
  </code></pre>
  
  <p>In the above 03-Jan and 06-Jan do not have any entries. </p>
  
  <p>Would like to fill the missing entries with default values (say, zero for orders, amount etc.), or carry the last vaue forward (e.g, 03-Jan will reuse 02-Jan values and 06-Jan will reuse the 05-Jan values etc..)</p>
  
  <p>What is the best/optimal way to fill-in such gaps of missing dates data with such default values?</p>
  
  <p>The answer <a href="https://stackoverflow.com/questions/16518505/efficiently-inserting-default-missing-rows-in-a-data-table">here</a> suggests using <code>allow.cartesian = TRUE</code>, and <code>expand.grid</code> for missing weekdays - it may work for weekdays (since they are just 7 weekdays) - but not sure if that would be the right way to go about dates as well, especially if we are dealing with multi-year  data.</p>