[英]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. 我正在尝试使用日期和月份在R中创建不包含年份的日期类。 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. 您当前使用format
是用于输入。 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
这正是您用format
包装的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.