[R] Filtering based on the occurrence
Farnoosh Sheikhi
farnoosh_81 at yahoo.com
Wed Mar 30 01:52:14 CEST 2016
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", "3", "3", "3", "4", "4", "5", "5", "5", "5")dates<-seq(as.Date('2011-01-01'),as.Date('2011-01-12'),by = 1) deps<-c("A", "B", "C", "C", "D", "A", "F", "G", "A", "F", "A", "D")df <- data.frame(Subject, dates, deps)df
The final data should look like this:final<-c("2 2011-01-02 B","2 2011-01-03 C","3 2011-01-05 D","3 2011-01-06 A","4 2011-01-07 F","4 2011-01-08 G","5 2011-01-10 F","5 2011-01-11 A","5 2011-01-12 D") Thank you tons for your help.
Farnoosh
[[alternative HTML version deleted]]
More information about the R-help
mailing list