title: R: How to find the first non-zero element in a dataframe by group
body: <p>I have the following dataframe</p>
  
  <pre><code>ID     date        Flag
  ABC    2018-03-21  N/A
  ABC    2018-03-17  0
  ABC    2018-03-12  0 
  ABC    2018-03-10  0 
  ABC    2018-03-09  1
  ABC    2018-03-08  0
  ABC    2018-03-07  1
  DEF    2018-03-24  N/A
  DEF    2018-03-21  0
  DEF    2018-03-20  0
  DEF    2018-03-14  0
  DEF    2018-03-13  0
  DEF    2018-03-12  0
  DEF    2018-03-11  0
  DEF    2018-03-10  0
  DEF    2018-03-09  0       
  DEF    2018-03-08  1       
  DEF    2018-03-07  0
  DEF    2018-03-06  0
  DEF    2018-03-05  1
  </code></pre>
  
  <p>I want to subset this dataset such that I will only have rows between the first record and the the first 1 value in the flag column for each group and if there is no 1, that group should not appear at all. </p>
  
  <p>Something like this:</p>
  
  <pre><code>ID     date        Flag
  ABC    2018-03-21  N/A
  ABC    2018-03-17  0
  ABC    2018-03-12  0 
  ABC    2018-03-10  0 
  DEF    2018-03-24  N/A
  DEF    2018-03-21  0
  DEF    2018-03-20  0
  DEF    2018-03-14  0
  DEF    2018-03-13  0
  DEF    2018-03-12  0
  DEF    2018-03-11  0
  DEF    2018-03-10  0
  DEF    2018-03-09  0          
  </code></pre>
  
  <p>I saw some answers at <a href="https://stackoverflow.com/questions/40515180/dplyr-how-to-find-the-first-non-missing-string-by-groups">Dplyr : how to find the first-non missing string by groups?</a> 
  But it is for non-missing and I have both non-missing and 0 values. </p>