title: Sequence Numbers with Dplyr
body: <p>Given the dataset below:</p>
  
  <pre><code>tmp = data.frame(id = c(1,1,1, 2, 2, 3),
               cont_date = c("2015-01-01", "2016-01-01", "2017-01-01", "2017-01-01", "2015-01-01", "2016-01-01"))
  library(lubridate)
  tmp$cont_date = ymd(tmp$cont_date)
  </code></pre>
  
  <p>I am probably missing something obvious, but I expected the following code</p>
  
  <pre><code>tbl_df(tmp) %&gt;% group_by(id) %&gt;% arrange(cont_date) %&gt;% mutate(seqnum = 1:length(id))
  </code></pre>
  
  <p>to create a sequence number of each block of records, which are grouped by id.  Instead, this is what I get:</p>
  
  <pre><code>      id  cont_date seqnum
  1  1 2015-01-01      1
  2  2 2015-01-01      2
  3  1 2016-01-01      3
  4  3 2016-01-01      4
  5  1 2017-01-01      5
  6  2 2017-01-01      6
  </code></pre>
  
  <p>I dont want to a sequence number of all records, but for each block.  It looks like the <code>group_by</code> portion is being ignored.</p>
  
  <p>Any help will be much appreciated.</p>