I have 20 years worth of weather data, but I'm only interested in the patterns per year. I don't care how June 1995 is different from June 2011, for example. Instead, I want to have 20 values for June 1, 20 values for June 2, etc.
My question: How do I drop the year portion of a date object, keep the month AND day, while also maintaining the sequential properties of dates? My ultimate goal is a long list of repeated mm/dd values corresponding each to the outcome variable. I'll treat the mm/dd like factors, but in the correct order.
# Given this:
as.Date(c("2014-06-01","1993-06-01", "2013-06-03", "1999-01-31"), "%Y-%m-%d")
# I want to get this:
"06-01" "06-01" "06-03" "01-31"
# That will sort like this
"01-31" "06-01" "06-01" "06-03"
Little hacks like using sub() to drop the year and convert the dash to a decimal doesn't work because then the 1st of the month is the same as the 10th of the month. I also tried turning the dates into character strings, removing the year, and then turning it back into a date... that just made everything year 2014.
Does this work?
temp<-as.Date(c("2014-06-01","1993-06-01", "2013-06-03", "1999-01-31"), "%Y-%m-%d")
x<-format(temp, format="%m-%d")
x
[1] "06-01" "06-01" "06-03" "01-31"
sort(x)
[1] "01-31" "06-01" "06-01" "06-03"