Displaying 2 results from an estimated 2 matches for "keep_row".
Did you mean:
keep_rows
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
...erfectly :)?Best,Farnoosh
On Wednesday, March 30, 2016 1:13 AM, Jim Lemon <drjimlemon at gmail.com> wrote:
Hi Farnoosh,
Despite my deep suspicion 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)...