Reputation: 1295
I am trying to create a date class without the year in R using a date and month. For example:
frame <- paste(c("March", "December", "January"), c(9,16,27))
as.Date(frame, format = "%B %d")
This automatically outputs the current year:
[1] "2014-03-09" "2014-12-16" "2014-01-27"
Is there any way to create a date class and suppress the year? I would like to do this in order to look through a frame of dates from multiple years to create a 'quarter' indicator. Thanks.
Upvotes: 1
Views: 270
Reputation: 20811
the way you are currently using format
is for input. For formatting the output, try:
frame <- paste(c("March", "December", "January"), c(9,16,27))
format(as.Date(frame, format = "%B %d"), '%B %d')
[1] "March 09" "December 16" "January 27"
which is exactly what you had wrapped in format
Upvotes: 2