R:无法为xts对象计算acf

时间:2017-04-28 17:00:27

标签: r xts

我有以下xts对象作为数据并计算acf会返回以下错误消息。

> acf(data_series)
Error in round(frequency) : non-numeric argument to mathematical function

数据系列如下:

structure(c(23081, 22739, 22725, 22472, 22956, 22900, 22662, 
22575, 22238, 22241, 22308, 22173, 22302, 22247, 22362, 22640, 
22609, 22611, 22761, 22805, 22815, 22875), index = structure(c(1478015096.961, 
1478101498.038, 1478187898.982, 1478274298.736, 1478533498.701, 
1478619898.962, 1478706297.971, 1478792699.88, 1478879098.9, 
1479138297.291, 1479224698.879, 1479311099.631, 1479397499.52, 
1479483899.146, 1479743097.896, 1479829497.495, 1479915896.634, 
1480002297.653, 1480088688, 1480347899.956, 1480434296.234, 1480520699.948
), tzone = "", tclass = c("POSIXct", "POSIXt")), .indexCLASS = c("POSIXct", 
"POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", class = c("xts", 
"zoo"), .Dim = c(22L, 1L), .Dimnames = list(NULL, "Close"))

现在,我很困惑为什么这不起作用,因为这些是每日数据。有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:4)

这有效:

acf(coredata(data_series))

说明:您的数据系列是xts对象,而不是数字向量或矩阵类型。这就是为什么你得到一个错误,即使底层数据真的是数字。应用于coredata()对象的xts返回基础(通常是数字类型)矩阵。

> class(data_series)
[1] "xts" "zoo"

> class(coredata(data_series))
[1] "matrix"