【问题标题】:Why does "xts" in R cannot recognize my date series?为什么 R 中的“xts”无法识别我的日期系列?
【发布时间】:2014-05-19 11:24:46
【问题描述】:

出生日期和日期来自同一个文件并共享相同的长度。 日期格式似乎很好。但是xts 无法将其识别为日期,为什么?!感谢您的帮助!

dates <- read.xlsx("TimeSeriesCourseworkData.xls", 1,colIndex=1,as.data.frame=TRUE)
dates

        Month
1  2009-01-01
2  2009-02-01
3  2009-03-01
4  2009-04-01
............

26 2011-02-01
27 2011-03-01
28 2011-04-01
29 2011-05-01
30 2011-06-01

births <- xts(births, order.by = dates) 
# Error in xts(births, order.by = dates) : 
# order.by requires an appropriate time-based object

births <- xts(births, order.by = as.Date(dates))
# Error in as.Date.default(dates) : 
# do not know how to convert 'dates' to class “Date”

【问题讨论】:

  • str(dates) 和 str(births) 在执行births之前的输出是什么

标签: r math statistics time-series xts


【解决方案1】:

dates 是一个 1 列的 data.frame。 as.Date 和 xts' order.by 参数需要向量。

births <- xts(births, dates$Month)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    相关资源
    最近更新 更多