【问题标题】:Why does R impute the 12th of the month when formatting a year as a Date [duplicate]为什么R在将年份格式化为日期时会计算每月的12号[重复]
【发布时间】:2018-01-12 20:48:31
【问题描述】:

如果有人调用as.Date(as.character(2002:2013), format='%Y'),我会在 R 中注意到输出是

[1] "2002-01-12" "2003-01-12" "2004-01-12" ...

我希望 R 给我一个月的第一天。我可以提供整个日期,paste(2002, '01', '01', sep='-'),但我很好奇为什么只有年份的格式会计算当月的 12 号以及其他解决方案。

【问题讨论】:

  • 你也可以使用ISOdate(2002:2013,1,1)

标签: r date


【解决方案1】:

啊,刚刚找到我的答案:Date 对象(月/日)的缺失部分是根据今天的日期(系统日期)估算的。

【讨论】:

    猜你喜欢
    • 2018-10-24
    • 2014-04-26
    • 2013-04-01
    • 2014-03-21
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 2014-12-29
    • 1970-01-01
    相关资源
    最近更新 更多