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]]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.