title: dplyr mutate calling another dataframe
body: <p>I would like to mutate a dataframe by applying a function which calls out to another dataframe. I can acheive this in a few different ways, but would like to know how to do this 'properly'.</p>
  
  <p>Here is an example of what I'm trying to do. I have a dataframe with some start times, and a second with some timed observations. I would like to return a dataframe with the start times, and the number of observations that occur within some window after the start time. e.g.</p>
  
  <pre><code>set.seed(1337)
  df1 &lt;- data.frame(id=LETTERS[1:3], start_time=1:3*10)
  df2 &lt;- data.frame(time=runif(100)*100)
  lapply(df1$start_time, function(s) sum(df2$time&gt;s &amp; df2$time&lt;(s+15)))
  </code></pre>
  
  <p>The best I've got so far with dplyr is the following (but this loses the identity variables):</p>
  
  <pre><code>df1 %&gt;% 
      rowwise() %&gt;%
      do(count = filter(df2, time&gt;.$start_time, time &lt; (.$start_time + 15))) %&gt;%
      mutate(n=nrow(count))
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Source: local data frame [3 x 2]
  Groups: &lt;by row&gt;
  
  # A tibble: 3 × 2
                    count     n
                   &lt;list&gt; &lt;int&gt;
  1 &lt;data.frame [17 × 1]&gt;    17
  2 &lt;data.frame [18 × 1]&gt;    18
  3 &lt;data.frame [10 × 1]&gt;    10
  </code></pre>
  
  <p>I was expecting to be able to do this:</p>
  
  <pre><code>df1 &lt;- data.frame(id=LETTERS[1:3], start_time=1:3*10)
  df2 &lt;- data.frame(time=runif(100)*100)
  df1 %&gt;% 
      group_by(id) %&gt;% 
      mutate(count = nrow(filter(df2, time&gt;start_time, time&lt;(start_time+15))))
  </code></pre>
  
  <p>but this returns the error:</p>
  
  <pre><code>Error: comparison (6) is possible only for atomic and list types
  </code></pre>
  
  <p>What is the dplyr way of doing this?</p>