title: Use a specific value in summarise (dplyr) without filtering it out
body: <p>I am trying to compare a new algorithm result versus an old one. I need to know approximately how many days of a difference the new algorithm has in predicting a "D" versus the old one. </p>
  
  <p>I can't seem to figure out how to point to the first row (day) that contains a 'D'  (min(day) and new == 'D') without filtering (I was able to grab the row using a double filter due to the grouping, but not use it). I want to use it in <code>summarise</code> using <code>dplyr</code> which is why I have included pseudo code similar to where i am currently at in my own dataset. 
  In my data there are groups of varying length (number of days) for each ID, which is why I made groups of different lengths in the example. </p>
  
  <pre class="lang-r prettyprint-override"><code>library(dplyr)
  
  id = c(123,123,123,123,123,456,456,456,456)
  old = c('S','S','S','S','D','S','S','D','D')
  new = c('S','S','D','D','D','S','D','D','D')
  day = c(1,2,3,4,5,1,2,3,4)
  data = data.frame(id,old,new,day)
  data
  #&gt;    id old new day
  #&gt; 1 123   S   S   1
  #&gt; 2 123   S   S   2
  #&gt; 3 123   S   D   3
  #&gt; 4 123   S   D   4
  #&gt; 5 123   D   D   5
  #&gt; 6 456   S   S   1
  #&gt; 7 456   S   D   2
  #&gt; 8 456   D   D   3
  #&gt; 9 456   D   D   4
  
  d = data %&gt;%
    group_by(id)%&gt;%
    arrange(day,.by_group=T)%&gt;%
    add_tally(new=='S',name='S')%&gt;%
    add_tally(new=='D',name='D')%&gt;%
    group_by(id,S,D)
    # summarise(diff = (day of 1st old D) - (day of 1st new D) )
  
  
  #Expected Outcome
  ido = c(123,456)
  S = c(2,1)
  D = c(3,3)
  diff = c(2,1)
  
  
  outcome = data.frame(ido,S,D,diff)
  outcome
  #&gt;   ido S D diff
  #&gt; 1 123 2 3    2
  #&gt; 2 456 1 3    1
  </code></pre>
  
  <p><sup>Created on 2019-12-26 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>