[R] Select range of dates

From: Ian Broom <broomian_at_gmail.com>
Date: Sun 08 Oct 2006 - 03:40:47 GMT


Hello,

This is likely fairly silly question, and I apologize to whomever takes the time to respond.

I am a relatively new user of R, on Windows XP, version 2.3.1.

Say I have a data table that looks like the following:

x

         Date Location Amount Blue Green

1  01/01/2001  Central    1817  TRUE FALSE
2  01/02/2001  Central   20358 FALSE  TRUE
3  05/08/2001  Central   16245 FALSE  TRUE
4  02/02/2002  Western     112  TRUE FALSE
5  21/03/2002  Western   98756  TRUE FALSE
6  01/04/2002  Western 1598414 FALSE  TRUE
7  07/01/2001  Western    1255 FALSE  TRUE
8  20/10/2003  Central   16289  TRUE FALSE
9  21/10/2003  Eastern   10000 FALSE  TRUE
10 22/10/2003  Eastern   98737 FALSE  TRUE
11 23/10/2003  Eastern  198756  TRUE FALSE
12 24/10/2003  Eastern   98756 FALSE  TRUE
13 25/10/2003  Eastern   65895  TRUE FALSE
14 26/10/2003  Eastern 2142266 FALSE  TRUE
15 27/10/2003    North   98756  TRUE FALSE
16 28/10/2003    North  548236 FALSE  TRUE

and I want to do some summaries by Fiscal year (or FY quarter). Reading manuals and such, I cobbled this less than satisfactory bit together to start to build a factor representing a fiscal year split:

y<-as.Date(x$Date,"%d/%m/%Y")
y<-as.matrix(y)
y$FY0203<-ifelse((y>=(as.Date("2002-03-21")))&(y<=(as.Date ("2003-04-01"))),"TRUE","FALSE") the values seem correct, but aside from ugly, the data is not in the proper format - with some more effort I might fix that... But my question is: is there a more simple function available to select a range of dates? Or, at least, a more elegant approach?

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch 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. Received on Sun Oct 08 13:47:35 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 08 Oct 2006 - 04:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.