Hello, See my problem below. a<-data.frame(c("s","c","c","n","n","n"),c(rep(1,3),rep(2,3)),c(rep(2,3),rep(1,3)),c("01/01/1999","10/02/2000","13/02/2000","11/02/2000","15/02/2000","23/02/2000")) colnames(a)<-c("var1","var2","var3","var4") > a var1 var2 var3 var4 1 s 1 2 01/01/1999 2 c 1 2 10/02/2000 3 c 1 2 13/02/2000 4 n 2 1 11/02/2000 5 n 2 1 15/02/2000 6 n 2 1 23/02/2000
I want to select the observations whose difference of "var4" is less than 7 for the cases with the same values of var1,var2 andvar3. The obervations have the same var1, var2 and var3 are, part1 (obs2 and obs3) and part2 (obs4,obs5, and obs6). For obs2 and obs3, their date difference is less than 7, so we donot need to delete any of them. For obs4,obs5, and obs6,we can see that obs6 should be deleted becuase its date is over 7 dyas longer than obs4. So the final dataset should obs1,obs2,obs3,obs4, and obs5. I have a lot of observations in my dataset, so i hope to do this automatically. Any ideas on this? Thanks. -- ----------------- Jane Chang Queen's [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list 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.