[R] Convert day of year back into a date format.
Sam Albers
tonightsthenight at gmail.com
Tue Mar 27 20:12:48 CEST 2012
Hello,
I am having trouble figuring out how to convert a Day of Year integer
back into a Date format. For example I have the following:
date <- c('2008-01-01','2008-01-02','2008-01-03','2008-01-04','2008-01-05','2008-01-06','2008-01-07',
'2008-01-08','2008-01-09','2008-01-10','2008-01-11','2008-01-12','2008-01-13','2008-01-14','2008-01-15',
'2008-01-16','2008-01-17','2008-01-18','2008-01-19','2008-01-20','2008-01-21','2008-01-22','2008-01-23')
## this is then converted into a number corresponding to the day of
the year like so:
dayofyear <- strptime(date, format="%Y-%m-%d")$yday + 1
## Now my question is how do I get back to a date format (obviously
omitting the year).
## The end result is that I'd like to be able to have axis labels as
something like "Month-Day" or just "Month"
## instead of just an integers which isn't always intuitive for people
but I can't seem to figure out how to tell R
## to recognize an integer as a date.
Any suggestions?
Many thanks in advance!
Sam
More information about the R-help
mailing list