Skip to content
Prev 363199 / 398502 Next

Conditionally remove rows with logic

Hi Jennifer,
A very pedestrian method, but I think it does what you want.

remove_rows_after_1<-function(x) {
 nrows<-dim(x)[1]
 rtr<-NA
 rtrcount<-1
 got1<-FALSE
 thisID<-x$ID[1]
 for(i in 1:nrows) {
  if(x$ID[i] == thisID && got1) {
   rtr[rtrcount]<-i
   rtrcount<-rtrcount+1
  }
  if(x$ID[i] != thisID) {
   thisID<-x$ID[i]
   got1<-FALSE
  }
  if(x$ID[i] == thisID && x$LABEL[i]) got1<-TRUE
 }
 return(rtr)
}

The function returns the indices of rows to be removed.

Jim


On Mon, Aug 8, 2016 at 8:21 AM, Jennifer Sheng
<jennifer.sheng2002 at gmail.com> wrote: