title: How do I match data frames by time intervals?
body: <p>This is a problem that comes up often when I am importing raw data from data loggers. A temperature logger is set to record temperature every ten minutes, and a separate gas logger is set to record gas used in the last ten minute interval. I want to combine the data from these two loggers into a single data frame for plotting and analysis, but the times are not exactly aligned. I want to have one row in the data frame for each ten minute period, with the datetime showing the beginning of the time period.</p>
  
  <p>The temperature logger data looks like:</p>
  
  <blockquote>
  <pre><code>           datetime temperature
  2010-09-30 06:58:53 78.996
  2010-09-30 07:08:53 78.645
  2010-09-30 07:18:53 78.514
  2010-09-30 07:28:53 79.173
  2010-09-30 07:38:53 78.602
  </code></pre>
  </blockquote>
  
  <p>The gas logger data looks like:</p>
  
  <blockquote>
  <pre><code>           datetime gas
  2010-09-30 13:45:00  0
  2010-09-30 13:55:00  1
  2010-09-30 14:05:00  0
  2010-09-30 14:15:00  4
  2010-09-30 14:25:00  2
  </code></pre>
  </blockquote>
  
  <p>I want to combine the two data frames on ten minute intervals, so that the combined data looks like:</p>
  
  <blockquote>
  <pre><code>           datetime temperature gas  
  2010-09-30 13:40:00 NA          0
  2010-09-30 13:50:00 78.996      1
  2010-09-30 14:00:00 78.645      0
  2010-09-30 14:10:00 78.514      4
  2010-09-30 14:20:00 79.173      2
  2010-09-30 07:38:53 78.602      NA
  </code></pre>
  </blockquote>
  
  <p>Here's some code to get these two data frames:</p>
  
  <pre><code>temps &lt;- data.frame(datetime=c("2010-09-30 06:58:53",
  "2010-09-30 07:08:53","2010-09-30 07:18:53",
  "2010-09-30 07:28:53","2010-09-30 07:38:53"),
   temperature=c(78.996,78.645,78.514,79.173,78.602),
  stringsAsFactors=FALSE)
  temps$datetime &lt;- strptime(temps$datetime, format="%Y-%m-%d %H:%M:%S")
  gas &lt;- data.frame(datetime=c("2010-09-30 13:45:00",
  "2010-09-30 13:55:00","2010-09-30 14:05:00",
  "2010-09-30 14:15:00","2010-09-30 14:25:00"),
  gas=c(0,1,0,4,2),stringsAsFactors=FALSE)
  gas$datetime &lt;- strptime(temps$datetime, format="%Y-%m-%d %H:%M:%S")
  </code></pre>