假设我有以下数据集:
date <- structure(c(1986, 1986.08333333333, 1986.16666666667), class = "yearmon")
return <- structure(c(0.000827577426231287, 0.00386371801344005, 0.00382634819565989
), .Dim = 3L, .Dimnames = list(c("1986-01", "1986-02", "1986-03"
)))
我使用以下内容将返回array
转换为zoo/zooreg
对象:
zooreg(return, order.by = date)
它提供了正确的输出并带有警告:
Jan 1986 Feb 1986 Mar 1986
0.0008275774 0.0038637180 0.0038263482
警告讯息: 在动物园(数据,order.by,频率): “order.by”和“frequency”不匹配:“频率”被忽略
该系列是严格定期的,order.by
和frequency
应该匹配,但我仍然无法弄清楚为什么会有警告。
答案 0 :(得分:1)
根据文件(?yearmon
):
“yearmon”类用于表示月度数据。在内部,它保存数据为年份加0表示1月,1月12日表示2月,2月12日表示3月等等,以便其内部表示与频率= 12的ts类相同。
通话:
zooreg(return, order.by = date)
相当于调用
zoo(return, order.by = date, frequency = 1)
根据zoo
下的Arguments::frequency
文档:
如果指定,则检查order.by和frequency是否符合。
因此警告。要摆脱警告,请使用
z <- zooreg(return, order.by = date, frequency = 12)
或
z <- zoo(return, order.by = date, frequency = 12)
这两个都将返回类zooreg
的对象:
str(z)
‘zooreg’ series from Jan 1986 to Mar 1986
Data: Named num [1:3] 0.000828 0.003864 0.003826
- attr(*, "names")= chr [1:3] "1986-01" "1986-02" "1986-03"
Index: Class 'yearmon' num [1:3] 1986 1986 1986
Frequency: 12
根据文档(?zoo
),
这是“动物园”的子类,依赖于“动物园”系列带有额外的“频率”属性(必须符合该系列的索引)
我相信这就是你想要的。
请注意使用
调用不匹配的“order.by”和“frequency”z <- zooreg(return, order.by = date)
您只获得zoo
个对象:
str(z)
‘zoo’ series from Jan 1986 to Mar 1986
Data: Named num [1:3] 0.000828 0.003864 0.003826
- attr(*, "names")= chr [1:3] "1986-01" "1986-02" "1986-03"
Index: Class 'yearmon' num [1:3] 1986 1986 1986