문제

transform() removes the class "xts" qualifier from my xts object:

> class(myxts)
[1] "xts" "zoo"
> myxts = transform(myxts, ABC = 1)
> class(myxts)
[1] "zoo"

Why is that?

도움이 되었습니까?

해결책

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>

You could simply wrap your transform calls in as.xts, or your example could be written as myxts$ABC <- 1.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top