Open linc0380 opened 4 months ago
For what it's worth, you can get data from FRED in an xts object using quantmod.
data <- quantmod::getSymbols("SP500", src = "FRED", auto.assign = FALSE)
The first line in the output from xts(x = data$SP500, order.by = data$date)
is the column name, which is a monstrosity because data$SP500
is a vector and doesn't have a column name. You can use xts(data["SP500"], data$date)
if you want the column name to be "SP500".
I can see how that weird column name is confusing, so I'll change the code so the result of xts()
doesn't add a column name for a vector input.
Thanks for this! Your answer is very illuminating indeed. I didn't realise that data$SP500
returns a simple numeric vector while data["SP500"]
preserves the type (and its name!). That a terrific lesson to have learnt today. I wasn't aware of quantmod
's capabilities either. Thanks a million for the pointer!
Description
I am trying to convert a tibble to an
xts
object. The conversion works fine withas.xts()
. The behaviour usingxts()
is unexpected, however.A dataset in
xlsx
format is downloaded from the St. Louis Fed data archive. Go to https://fred.stlouisfed.org/graph/?g=1icUr, click on Download, and select Excel. I modified the resultingxlsx
sheet by deleting all auxiliary information in rows 1 to 10, renaming the date columndate
. That file is saved asSP500.xlsx
. I am not sure how I can make this file available to save you from replicating these steps.The
xlsx
file is imported by means ofThe resulting structure is
Expected behavior
The following conversion fine:
resulting in
Minimal, reproducible example
Yet using
results in an
xts
object with the same structure yet with outputI am not sure what the first output line means.
Session Info