title: Summarise to return the length by group
body: <p>I want to add a new column to the data frame below that calculates maximum dry spell length for each month.
  This is what my data frame looks like:</p>
  
  <pre><code>   day month year  rr spell spell1
       1     1 1981  0   dry      1
       2     1 1981  0   dry      1
       3     1 1981  0   dry      1
       4     1 1981  1.1 dry      0
       5     1 1981  0   dry      1
       6     1 1981  0   dry      1
       7     1 1981  0   dry      1
       8     1 1981  0   dry      1
       9     1 1981  2.7 dry      0
      10     1 1981  0   dry      1
  </code></pre>
  
  <p>This is the output I need:</p>
  
  <pre><code> month year  spell_length
       1 1981      3
       1 1981      4
       1 1981      1
  </code></pre>
  
  <p>this is what I have done so far:</p>
  
  <pre><code>group_by(df, year, month, spell1) %&gt;% 
      summarise(spell2 = sum(spell1, na.rm = TRUE))
  </code></pre>
  
  <p>and this is the result:</p>
  
  <pre><code>  year month spell1 spell_length
    &lt;int&gt; &lt;int&gt;  &lt;dbl&gt;  &lt;dbl&gt;
  1  1981     1      1     31
  2  1981     2      0      0
  3  1981     2      1     27
  4  1981     3      0      0
  5  1981     3      1     25
  6  1981     4      0      0
  </code></pre>
  
  <p><strong>data</strong></p>
  
  <pre><code>df &lt;- read.table(h= T, text="day month year  rr spell spell1
  1     1 1981  0   dry      1
  2     1 1981  0   dry      1
  3     1 1981  0   dry      1
  4     1 1981  1.1 dry      0
  5     1 1981  0   dry      1
  6     1 1981  0   dry      1
  7     1 1981  0   dry      1
  8     1 1981  0   dry      1
  9     1 1981  2.7 dry      0
  10     1 1981  0   dry      1")
  </code></pre>