简体   繁体   中英

Suppress year in as.Date in R

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM