Re: [R] Conditionally remove rows with logic

2016-08-10 Thread jim holtman
try this: > input <- read.table(text = "ID TIME LABEL + 100 + 130 + 160 + 190 + 112 1 + 115 0 + 118 0 + 200 + 23

Re: [R] Conditionally remove rows with logic

2016-08-08 Thread MacQueen, Don
Assuming that within each ID the data is sorted by increasing TIME, and that LABEL==1 occours only once within each ID. Then I would try something like this. Suppose that your data is in a data frame named "df". df.keep <- logical() for (id in unique(df$ID)) { df.tmp <- subset(df, df$ID==id)

Re: [R] Conditionally remove rows with logic

2016-08-08 Thread Jim Lemon
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] !=

[R] Conditionally remove rows with logic

2016-08-07 Thread Jennifer Sheng
Dear all, I need to remove any rows AFTER the label becomes 1. For example, for ID 1, the two rows with TIME of 15 & 18 should be removed; for ID 2, any rows after time 6, i.e., rows of time 9-18, should be removed. Any suggestions? Thank you very much! The current dataset looks like the follo