You must remember that a date is a number format that represents the number of days that have passed since the "start" of calculating the internal date:
> str(Date) Class 'Date' num [1:10] 14245 14360 14475 14590 14705 ...
This is the same as in EXCEL if you want a link. Therefore, the solution with the format is quite correct.
Now, if you want to set the first date of the year as October 1, you can build such an index of the year as follows:
redefine.year <- function(x,start="10-1"){ year <- as.numeric(strftime(x,"%Y")) yearstart <- as.Date(paste(year,start,sep="-")) year + (x >= yearstart) - min(year) + 1 }
Test Code:
Start <- as.Date("2009-1-1") Stop <- as.Date("2011-11-1") Date <- seq(Start,Stop,length.out=10) data.frame( Date=as.character(Date), year=redefine.year(Date))
gives
Date year 1 2009-01-01 1 2 2009-04-25 1 3 2009-08-18 1 4 2009-12-11 2 5 2010-04-05 2 6 2010-07-29 2 7 2010-11-21 3 8 2011-03-16 3 9 2011-07-09 3 10 2011-11-01 4
source share