title: Find which interval row in a data frame that each element of a vector belongs in
body: <p>I have a vector of numeric elements, and a dataframe with two columns that define the start and end points of intervals. Each row in the dataframe is one interval. I want to find out which interval each element in the vector belongs to.</p>
  
  <p>Here's some example data:</p>
  
  <pre><code># Find which interval that each element of the vector belongs in
  
      library(tidyverse)
      elements &lt;- c(0.1, 0.2, 0.5, 0.9, 1.1, 1.9, 2.1)
  
      intervals &lt;-  frame_data(~phase, ~start, ~end,
                                 "a",     0,     0.5,
                                 "b",     1,     1.9,
                                 "c",     2,     2.5)
  </code></pre>
  
  <p>The same example data for those who object to the tidyverse:</p>
  
  <pre><code>elements &lt;- c(0.1, 0.2, 0.5, 0.9, 1.1, 1.9, 2.1)
  
  intervals &lt;- structure(list(phase = c("a", "b", "c"), 
                              start = c(0, 1, 2), 
                              end = c(0.5, 1.9, 2.5)), 
                         .Names = c("phase", "start", "end"), 
                         row.names = c(NA, -3L), 
                         class = "data.frame")
  </code></pre>
  
  <p>Here's one way to do it:</p>
  
  <pre><code>    library(intrval) 
      phases_for_elements &lt;- 
      map(elements, ~.x %[]% data.frame(intervals[, c('start', 'end')])) %&gt;% 
        map(., ~unlist(intervals[.x, 'phase'])) 
  </code></pre>
  
  <p>Here's the output:      </p>
  
  <pre><code>    [[1]]
      phase 
        "a" 
  
      [[2]]
      phase 
        "a" 
  
      [[3]]
      phase 
        "a" 
  
      [[4]]
      character(0)
  
      [[5]]
      phase 
        "b" 
  
      [[6]]
      phase 
        "b" 
  
      [[7]]
      phase 
        "c" 
  </code></pre>
  
  <p>But I'm looking for a simpler method with less typing. I've seen <code>findInterval</code> in related questions, but I'm not sure how I can use it in this situation. </p>