Displaying 2 results from an estimated 2 matches for "start_keep".
Did you mean:
start_eip
2016 Mar 29
2
Filtering based on the occurrence
Hello,?
I have a data set similar to below and I wanted to keep the observations after the first occurrence of these department: "B", "D", "F".For example for ID=2, the observation with deps=B and anything after will be kept in the data. For ID=3, observations with deps=D and anything after will be included.
Subject<- c("2", "2", "2",
2016 Mar 31
0
Filtering based on the occurrence
...on that this answer will solve a useless
problem, try this:
last_subject<-0
keep_deps<-c("B","D","F")
keep_rows<-NULL
for(rowindex in 1:dim(df)[1]) {
if(df[rowindex,"Subject"] != last_subject) {
? last_subject<-df[rowindex,"Subject"]
? start_keeping<-0
}
if(df[rowindex,"deps"] %in% keep_deps) start_keeping<-1
if(start_keeping) keep_rows<-c(keep_rows,rowindex)
}
final<-matrix(unlist(lapply(df[keep_rows,],as.character)),ncol=3)
I find it terribly hard to ignore puzzles.
Jim
On Wed, Mar 30, 2016 at 10:52 AM, Farnoo...