[R] Selecting data based on the range of dates

Belle ping.yi at gmail.com
Thu Feb 24 23:12:49 CET 2011


I think I got it, I post it here see if you have better way, please let me
know.

index <- rep(0, length(mydata[,1]))
index[as.Date(mydata3$Date) < as.Date("2006-11-30 23:29:29 PM") &
as.Date(mydata3$Date) > as.Date("2006-09-01 00:00:00 AM")] <- 1
index[as.Date(mydata3$Date) < as.Date("2007-11-30 23:29:29 PM") &
as.Date(mydata3$Date) > as.Date("2007-09-01 00:00:00 AM")] <- 1
index[as.Date(mydata3$Date) < as.Date("2008-11-30 23:29:29 PM") &
as.Date(mydata3$Date) > as.Date("2008-09-01 00:00:00 AM")] <- 1
index[as.Date(mydata3$Date) < as.Date("2009-11-30 23:29:29 PM") &
as.Date(mydata3$Date) > as.Date("2009-09-01 00:00:00 AM")] <- 1
index[as.Date(mydata3$Date) < as.Date("2010-11-30 23:29:29 PM") &
as.Date(mydata3$Date) > as.Date("2010-09-01 00:00:00 AM")] <- 1

Thanks
-- 
View this message in context: http://r.789695.n4.nabble.com/Selecting-data-based-on-the-range-of-dates-tp3323452p3323536.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list