我有一个日内系列(以xts为单位),我希望将其汇总到每日频率:apply.daily(mean(asd))
。它给了我:
try.xts出错(x,错误="必须是xts-coercible或timeBased"): 必须是xts-coercible或timeBased
有人知道这个错误可能来自哪里吗?
> head(asd)
EUR.USD.Close
2015-01-02 01:00:00 1.20875
2015-01-02 01:01:00 1.20870
2015-01-02 01:02:00 1.20880
2015-01-02 01:03:00 1.20890
2015-01-02 01:04:00 1.20885
2015-01-02 01:05:00 1.20885
> str(asd)
An ‘xts’ object on 2015-01-02 01:00:00/2015-01-30 22:59:00 containing:
Data: num [1:28140, 1] 1.21 1.21 1.21 1.21 1.21 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr "EUR.USD.Close"
Indexed by objects of class: [POSIXct,POSIXt] TZ:
xts Attributes:
List of 4
$ from : chr "20150421 09:00:00"
$ to : chr "20150501 09:00:00"
$ src : chr "IB"
$ updated: POSIXct[1:1], format: "2015-06-07 01:46:37"
答案 0 :(得分:2)
语法为
apply.daily(asd, mean)
# EUR.USD.Close
#2015-01-02 01:05:00 1.208808
有关详情,请查看该页面中的?apply.daily
和示例。
我可以用错误的代码语法重现错误
apply.daily(mean(asd))
#Error in try.xts(x, error = "must be either xts-coercible or timeBased") :
# must be either xts-coercible or timeBased