This would seem to be a simple task but I’m having difficulty executing it as well as finding examples of how it is done in R.
I have a data frame with about 75K records. One field has dates and it goes back about 11 years. I’ve used the following code to strip off the hours minutes seconds so I just have year-month-day
dat$date=round.POSIXt(dat$date,units="day")
I am now trying to create a new field “FiscalYear” based on dates such that if the date is between 2008-07-01 and 2009-06-30 it gets assigned FY09…then between 2009-07-01 and 2010-06-30 it gets assigned to FY10, etc…
The method I’ve been trying is with ifelse using >= && <= to set the date ranges but this isn’t working. Any thoughts?
Basically, what Ben said. Here’s an example of what that’d look like in practice. (I’ve used a
Dateclass object, since it sounds like you don’t need the hour/minute/second info.)