Hi: I want to give an index with all the dates between Sept. to Nov. as 1, and anything else is 0. It doesn't matter which year it is, as long as it is between Sept. to Nov, then set up to 1, otherwise is 0. My data frame looks like below: ID Date 201 1/1/05 6:07 AM 201 3/27/09 9:45 AM 201 9/29/09 8:44 AM 203 10/16/08 10:01 AM 203 10/28/08 9:45 AM 203 10/31/08 11:12 AM 203 11/7/08 11:32 AM 203 11/14/08 10:30 AM 203 11/19/08 10:40 AM 203 11/25/08 3:25 PM 203 12/4/08 10:48 AM 203 1/28/09 11:04 AM 203 2/12/09 3:15 PM 203 2/16/09 2:59 PM 203 2/24/09 2:45 PM 203 3/4/09 10:14 AM 203 3/27/09 11:36 AM 203 4/1/09 10:43 AM 203 4/16/09 2:28 PM 203 4/22/09 2:37 PM 203 4/29/09 10:48 AM 203 4/1/09 10:45 AM 203 12/3/09 9:07 AM 203 12/11/09 8:58 AM 203 1/7/10 8:53 AM Thanks -- View this message in context: http://r.789695.n4.nabble.com/Selecting-data-based-on-the-range-of-dates-tp3323452p3323452.html Sent from the R help mailing list archive at Nabble.com.
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.