title: How can I tell if a time point exists between a set of before and after times
body: <p>I was trying to answer a question on stack overflow (<a href="https://stackoverflow.com/questions/17222981/mapping-multiple-ids-using-r">Mapping multiple IDs using R</a>) when I got stuck with how to finish it. Namely, how can I test if there is a time point between a set of before and after time points. </p>
  
  <p>The user from the post did not make a reproducible example but here is what I came up with.  I want to test time points in <code>hidenic_file$hidenic_time</code> with the before and after times in dataframe <code>emtek_file</code> and return the <code>emtek_id</code>'s that match the time frame of each <code>hidenic_id</code>.  The poster didn't mention it but it seems like there is a possibility of multiple <code>emtek_id</code>'s being returned for each <code>hidenic_id</code>. </p>
  
  <pre><code>library(zoo)
  date_string &lt;- paste("2001", sample(12, 10, 3), sample(28,10), sep = "-")
  time_string &lt;- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26",
                   "23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26")
  
  entry_emtek &lt;- strptime(paste(date_string, time_string), "%Y-%m-%d %H:%M:%S")
  entry_emtek &lt;- entry_emtek[order(entry_emtek)]
  exit_emtek &lt;- entry_emtek + 3600 * 24
  emtek_file &lt;- data.frame(emtek_id = 1:10, entry_emtek, exit_emtek)
  
  hidenic_id &lt;- 110380:110479
  date_string &lt;- paste("2001", sample(12, 100, replace = TRUE), sample(28,100, replace = T), sep = "-")
  time_string &lt;- rep(c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26",
                   "23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26"),10)
  hidenic_time &lt;- strptime(paste(date_string, time_string), "%Y-%m-%d %H:%M:%S")
  hidenic_time &lt;- hidenic_time[order(hidenic_time)]
  hidenic_file &lt;- data.frame(hidenic_id, hidenic_time)
  
  ##Here is where I fail to write concise and working code to find what I want. 
  combined_file &lt;- list() 
  for(i in seq(hidenic_file[,1])) {
    for(j in seq(emtek_file[,1])) {
      if(length(zoo(1, emtek_file[j,2:3]) + zoo(1,hidenic_file[i,2])) == 0) {next}
      if(length(zoo(1, emtek_file[j,2:3]) + zoo(1,hidenic_file[i,2])) == 1) {combined_file[[i]] &lt; c(combinedfile[[i]],emtek_file[j,1])}
    }
    names(combined_file)[i] &lt;- hidenic_file[i,1]
  }
  </code></pre>