title: Data Table Solution in R To Trim
body: <pre><code>dataHAVE=data.frame("student"=c(1,1,1,1,2,2,2,2,3,3,3,3),
                      "time"=c(1:4,1:4,1:4),
                      "score"=c(NA,0,NA,NA,0,1,1,1,0,0,NA,NA),
                      "class"=c('A','A','B','B','A','A','A','A','A','A','A','B'))
  
  
  library(dplyr)
  dataWANT2 &lt;- group_by(dataHAVE,student) %&gt;% 
    slice(seq_len(min(which(score == 1), n()))) %&gt;% 
    filter(class != "B")
  </code></pre>
  
  <p>I come up with a dplyr solution to my problem which is to do this: </p>
  
  <p>if score = 1, delete all rows that follow for that student but keep the first row that equals to 1. </p>
  
  <p>if class = 'B' delete that row and all others that come after it for that student.</p>
  
  <p>I am searching for a data.tale solution to this.</p>