Extracting the numerical values of a xts object

r xts
math picture math · Apr 5, 2014 · Viewed 11.1k times · Source

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")

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?

Answer

Joshua Ulrich picture Joshua Ulrich · Apr 5, 2014

Use coredata:

reg.curve.num <- coredata(Reg.curve)
# or, if you want a vector:
reg.curve.num <- drop(coredata(Reg.curve))