title: Time Series Interpolation
body: <p>I have two series of data (calibration and sample) and am trying to interpolate the calibration data from monthly to the frequency of the sample which randomly changes between minutes to seconds.</p>
  <p>I tried this (<a href="https://stackoverflow.com/questions/13073686/interpolating-timeseries">Interpolating timeseries</a>) and here's my code:</p>
  <pre><code>     require(zoo)
       
       zc &lt;- zoo(calib$MW2, calib$Date)    
       zs &lt;- zoo(sample$MW.2, sample$DateMW.2)
  
       z &lt;- merge(zc, zs)
  
       zc &lt;- zoo(calib$MW2, calib$Date)   
       zs &lt;- zoo(sample$MW.2, sample$DateMW.2)  
       
       # &quot;merge&quot; gets data frames only
       zc &lt;- data.frame(zc)
       zs &lt;- data.frame(zs)
  
       z &lt;- merge(zc, zs)
  
       z$zc &lt;- na.approx(z$zc, rule=2)
  
       df &lt;- z[index(zs),]
  </code></pre>
  <p><em><strong>Note:</strong></em> Convert outputs of <code>zoo</code> to <code>data.frame</code> (<code>zc</code> and <code>zs</code>) before merging.</p>
  <p>The problem is that instead of interpolation, it just repeats the calibration data-set; You can take a look at the part of the supposedly interpolated <code>df</code> and compare it to the original data above to confirm what I say;</p>
  <pre><code>     &gt; df
          zc       zs                date     
       1     60.84440 61.40373 2016-06-02 18:15:00
       2     58.85957 61.40373 2016-06-02 18:30:00
       3     57.49543 61.40373 2016-06-02 18:45:00
       4     56.32829 61.40373 2016-06-02 19:00:00
       5     56.84261 61.40373 2016-06-02 19:15:00
       6     57.76762 61.40373 2016-06-02 19:30:00
       7     59.58310 61.40373 2016-06-02 19:45:00
       8     59.95826 61.40373 2016-06-02 20:00:00
       9     60.84440 61.41549 2016-06-02 20:15:00
       10    58.85957 61.41549 2016-06-02 20:30:00
       11    57.49543 61.41549 2016-06-02 20:45:00
       12    56.32829 61.41549 2016-06-02 21:00:00
  </code></pre>
  <p>#Data:</p>
  <pre><code>     sample &lt;- structure(list(DateMW.2 = structure(1:15, .Label = c(&quot;6/2/2016 18:15:00&quot;, 
       &quot;6/2/2016 18:30:00&quot;, &quot;6/2/2016 18:45:00&quot;, &quot;6/2/2016 19:00:00&quot;, 
       &quot;6/2/2016 19:15:00&quot;, &quot;6/2/2016 19:30:00&quot;, &quot;6/2/2016 19:45:00&quot;, 
       &quot;6/2/2016 20:00:00&quot;, &quot;6/2/2016 20:15:00&quot;, &quot;6/2/2016 20:30:00&quot;, 
       &quot;6/2/2016 20:45:00&quot;, &quot;6/2/2016 21:00:00&quot;, &quot;6/2/2016 21:15:00&quot;, 
       &quot;6/2/2016 21:30:00&quot;, &quot;6/2/2016 21:45:00&quot;), class = &quot;factor&quot;), 
       MW.2 = c(61.40373, 61.41549, 61.41549, 61.42451, 61.42752, 
       61.42478, 61.43107, 61.42369, 61.40564, 61.41056, 61.40592, 
       61.39416, 61.38432, 61.3753, 61.3753)), .Names = c(&quot;DateMW.2&quot;, 
       &quot;MW.2&quot;), row.names = c(NA, 15L), class = &quot;data.frame&quot;)
  
  
       calib &lt;- structure(list(Date = structure(c(4L, 5L, 6L, 7L, 8L, 1L, 2L, 
       3L), .Label = c(&quot;10/31/2016 12:00:00&quot;, &quot;11/30/2016 12:00:00&quot;, 
       &quot;12/31/2016 12:00:00&quot;, &quot;5/31/2016 12:00:00&quot;, &quot;6/30/2016 12:00:00&quot;, 
       &quot;7/31/2016 12:00:00&quot;, &quot;8/31/2016 12:00:00&quot;, &quot;9/30/2016 12:00:00&quot;
       ), class = &quot;factor&quot;), MW2 = c(60.844402, 58.859566, 57.495434, 
       56.328285, 56.842606, 57.76762, 59.583103, 59.958263)), .Names = c(&quot;Date&quot;,     
       &quot;MW2&quot;), class = &quot;data.frame&quot;, row.names = c(NA, -8L))
  </code></pre>