R:为什么xts 对象在调用transform() 后变成zoo 对象? [英] R: Why an xts object becomes a zoo object after calling transform()?
本文介绍了R:为什么xts 对象在调用transform() 后变成zoo 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
transform() 从我的 xts 对象中删除类xts"限定符:
transform() removes the class "xts" qualifier from my xts object:
> class(myxts)
[1] "xts" "zoo"
> myxts = transform(myxts, ABC = 1)
> class(myxts)
[1] "zoo"
这是为什么?
推荐答案
transform
没有 xts 方法,所以调度了 zoo 方法.zoo 方法显式地创建了一个新的 zoo 对象.
There's no xts method for transform
, so the zoo method is dispatched. The zoo method explicitly creates a new zoo object.
> zoo:::transform.zoo
function (`_data`, ...)
{
if (is.null(dim(coredata(`_data`))))
warning("transform() is only useful for matrix-based zoo series")
zoo(transform.data.frame(data.frame(coredata(`_data`)), ...),
index(`_data`), attr(`_data`, "frequency"))
}
<environment: namespace:zoo>
您可以简单地将 transform
调用包装在 as.xts
中,或者您的示例可以编写为 myxts$ABC <- 1
.
You could simply wrap your transform
calls in as.xts
, or your example could be written as myxts$ABC <- 1
.
这篇关于R:为什么xts 对象在调用transform() 后变成zoo 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文