title: R: Subset a data frame based on times that are within a certain number of minutes of an observation window
body: <p>Let's say I have a data frame with  start and end time columns, a measurement column and a time of measurement column, like so:</p>
  
  <pre><code>     start         end    value                time
     9:01:00     9:02:00     30.6  2013-03-25 9:05:00
     9:01:00     9:02:00     30.8  2013-03-25 9:15:00
     9:46:00     9:46:00     28.2  2013-03-25 9:43:00
     9:46:00     9:46:00     28.9  2013-03-25 9:53:00
    10:54:00    10:59:00     13.4 2013-03-25 10:56:00
    10:54:00    10:59:00     13.8 2013-03-25 11:56:00
  </code></pre>
  
  <p>How might one subset this data frame to include only rows for which the time column is within the start and end time or ten minutes before the start time and ten minutes after the end time.  I'm choosing ten minutes arbitrarily, and would like to know how to do this for any amount of time before and after the start and end time.</p>
  
  <p>The resulting data frame would be as follows:    </p>
  
  <pre><code>     start         end    value                time
     9:01:00     9:02:00     30.6  2013-03-25 9:05:00
     9:46:00     9:46:00     28.2  2013-03-25 9:43:00
     9:46:00     9:46:00     28.9  2013-03-25 9:53:00
    10:54:00    10:59:00     13.4 2013-03-25 10:56:00
  </code></pre>
  
  <p>Is there a way to do this other than by subtracting/adding x number of minutes from the start/end column entries, and then subsetting based on whether or not the time column falls between these expanded windows?</p>
  
  <p>Currently, I have convert my time columns into POSIXlt format.  Unfortunately, this gives todays date to the times in the start and end column. </p>
  
  <p>here is the dput for the first data frame:</p>
  
  <pre><code>structure(list(start = structure(list(sec = c(0, 0, 0, 0, 0, 
  0), min = c(1L, 1L, 46L, 46L, 54L, 54L), hour = c(9L, 9L, 9L, 
  9L, 10L, 10L), mday = c(7L, 7L, 7L, 7L, 7L, 7L), mon = c(7L, 
  7L, 7L, 7L, 7L, 7L), year = c(113L, 113L, 113L, 113L, 113L, 113L
  ), wday = c(3L, 3L, 3L, 3L, 3L, 3L), yday = c(218L, 218L, 218L, 
  218L, 218L, 218L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("sec", 
  "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
  ), class = c("POSIXlt", "POSIXt")), end = structure(list(sec = c(0, 
  0, 0, 0, 0, 0), min = c(2L, 2L, 46L, 46L, 59L, 59L), hour = c(9L, 
  9L, 9L, 9L, 10L, 10L), mday = c(7L, 7L, 7L, 7L, 7L, 7L), mon = c(7L, 
  7L, 7L, 7L, 7L, 7L), year = c(113L, 113L, 113L, 113L, 113L, 113L
  ), wday = c(3L, 3L, 3L, 3L, 3L, 3L), yday = c(218L, 218L, 218L, 
  218L, 218L, 218L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("sec", 
  "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
  ), class = c("POSIXlt", "POSIXt")), value = c(30.6, 30.8, 28.2, 
  28.9, 13.4, 13.8), time = structure(list(sec = c(0, 0, 0, 0, 
  0, 0), min = c(5L, 15L, 43L, 53L, 56L, 56L), hour = c(9L, 9L, 
  9L, 9L, 10L, 11L), mday = c(25L, 25L, 25L, 25L, 25L, 25L), mon = c(2L, 
  2L, 2L, 2L, 2L, 2L), year = c(113L, 113L, 113L, 113L, 113L, 113L
  ), wday = c(1L, 1L, 1L, 1L, 1L, 1L), yday = c(83L, 83L, 83L, 
  83L, 83L, 83L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("sec", 
  "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
  ), class = c("POSIXlt", "POSIXt"))), .Names = c("start", "end", 
  "value", "time"), row.names = c(NA, -6L), class = "data.frame")
  </code></pre>
  
  <p>here is the dput for the second data frame</p>
  
  <pre><code>structure(list(start = structure(list(sec = c(0, 0, 0, 0), min = c(1L, 
  46L, 46L, 54L), hour = c(9L, 9L, 9L, 10L), mday = c(7L, 7L, 7L, 
  7L), mon = c(7L, 7L, 7L, 7L), year = c(113L, 113L, 113L, 113L
  ), wday = c(3L, 3L, 3L, 3L), yday = c(218L, 218L, 218L, 218L), 
      isdst = c(1L, 1L, 1L, 1L)), .Names = c("sec", "min", "hour", 
  "mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt", 
  "POSIXt")), end = structure(list(sec = c(0, 0, 0, 0), min = c(2L, 
  46L, 46L, 59L), hour = c(9L, 9L, 9L, 10L), mday = c(7L, 7L, 7L, 
  7L), mon = c(7L, 7L, 7L, 7L), year = c(113L, 113L, 113L, 113L
  ), wday = c(3L, 3L, 3L, 3L), yday = c(218L, 218L, 218L, 218L), 
      isdst = c(1L, 1L, 1L, 1L)), .Names = c("sec", "min", "hour", 
  "mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt", 
  "POSIXt")), value = c(30.6, 28.2, 28.9, 13.4), time = structure(list(
      sec = c(0, 0, 0, 0), min = c(5L, 43L, 53L, 56L), hour = c(9L, 
      9L, 9L, 10L), mday = c(25L, 25L, 25L, 25L), mon = c(2L, 2L, 
      2L, 2L), year = c(113L, 113L, 113L, 113L), wday = c(1L, 1L, 
      1L, 1L), yday = c(83L, 83L, 83L, 83L), isdst = c(1L, 1L, 
      1L, 1L)), .Names = c("sec", "min", "hour", "mday", "mon", 
  "year", "wday", "yday", "isdst"), class = c("POSIXlt", "POSIXt"
  ))), .Names = c("start", "end", "value", "time"), row.names = c(NA, 
  -4L), class = "data.frame")
  </code></pre>