[R] Operations with dates just as Month and Day and not Year
Camilo Mora
cmora at Dal.Ca
Sat Jan 24 06:21:52 CET 2015
Hi everyone,
I am trying to calculate the number of days between any two dates in a year regardless of the year. Specifically, image two dates:
MonDay1 <- "01-30" #January 30
MonDay2 <- "12-31" #December 31
I want the difference of those two dates to be
MonDay1- MonDay2=30 days #January is closer to December from the prior year than to the December in the year when January is.
FYI. this calculation is to count the number of days between any given date to the peak of the summer, which in the southern hemisphere can be around December.
Unfortunately, I have not been able to make R recognize a date as just Mon-Day. If I try:
MonDay1<-as.Date("01-30",format="%m-%d") # this automatically assigns the current year
[1] "2015-01-30"
This following code allows to define just Mon-Day but it is recognized as character:
format(strptime("07-30", format="%j"), format="%m-%d")
Any help will be greatly appreciated,
Thanks,
Camilo
More information about the R-help
mailing list