提取 xts 对象的数值 [英] Extracting the numerical values of a xts object
本文介绍了提取 xts 对象的数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提取一个 xts 对象的数值.我们来看一个例子
I want to extract the numerical values of a xts object. Let's look at an example
data <- new.env()
starting.date <- as.Date("2006-01-01")
nlookback <- 20
getSymbols("UBS", env = data, src = "yahoo", from = starting.date)
Reg.curve <- rollapply(Cl(data$UBS), nlookback, mean, align="right")
Reg.cuve
仍然是一个 xts 对象,但实际上我只是对运行方式感兴趣.如何修改 Reg.curve
以获得数值向量?
The Reg.cuve
is still a xts object but actually I'm just interested in the running means. How can I modify Reg.curve
to get a numerical vector?
推荐答案
使用coredata
:
reg.curve.num <- coredata(Reg.curve)
# or, if you want a vector:
reg.curve.num <- drop(coredata(Reg.curve))
这篇关于提取 xts 对象的数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文