title: How do I join on a filter instead of a key?
body: <p>I have a dataframe with a list of actions per year, like so - </p>
  
  <pre><code>print(df)
  
        id        actions      year       
        b           2       1995 
        c           156     1997 
        e           53      1996 
        f           109     1994 
  </code></pre>
  
  <p>I'd like to make a list of who had the most actions up to each year, so that it looks like this - </p>
  
  <pre><code>print(output)
  
        asofyear        id      actions      rank       
        1994            f       109          1
        1995            f       109          1
        1995            b       2            2
        1996            f       109          1
        1996            e       53           2
        1996            b       2            3
        1997            c       156          1
        1997            f       109          2
        1997            e       53           3
        1997            b       2            4
  </code></pre>
  
  <p>How do I do this join where it ranks every <code>id</code> for the <code>id</code> values with a year that is less than the <code>asofyear</code>. One idea I was thinking about was something like this -</p>
  
  <pre><code>asOfYear &lt;- seq(as.Date("1995-01-01"),as.Date("2000-01-01"),by="year")
  
  asOfYear %&gt;% 
      left_join(df, by = (asOfYear &lt;= year)) %&gt;%
      arrange(asofyear, actions) %&gt;%
      group_by(asofyear) %&gt;% 
      mutate(rank = row_number())
  </code></pre>
  
  <p>I don't know how to make that join key work though, but I would like to do this with <code>dplyr</code>.</p>