从 quantmod XTS 文件中检索行名称

Retreive row name from quantmod XTS file

我正在使用quantmod::getsymbols函数来检索stock index data for yahoo finance(如图所示,它被称为GDAXI.xts

现在我想访问左边的日期,但该列不在 GDAXI 文件中。我怎样才能访问日期?我尝试了不同的方法,但无法弄清楚,上次我尝试 d1.ts=GDAX[,0] 时它起作用了,但在这里不起作用。

谁能告诉我为什么?非常感谢您。

Datum=as.Date(GDAXI[,0])
Error in as.Date.default(GDAXI[, 0]) : 
  do not know how to convert 'GDAXI[, 0]' to class “Date”
Datum=GDAXI[,0]
View(Datum)
Warning in View :
  'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
Warning in View :
  'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
Warning message:
In as.data.frame.numeric(coredata(x), row.names, optional, ...) :
  'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
Datum=as.date(GDAXI[,0])
Error: could not find function "as.date"
In addition: Warning messages:
1: In as.data.frame.numeric(coredata(x), row.names, optional, ...) :
  'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
2: In as.data.frame.numeric(coredata(x), row.names, optional, ...) :
  'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
3: In as.data.frame.numeric(coredata(x), row.names, optional, ...) :
  'row.names' is not a character vector of length 0 -- omitting it. Will be an error!
Da.ts=GDAXI[,0]

我不熟悉 R 或 quantmod 但在我看来你想要做的是获取行的名称,而不是任何列数据,这可能是你的代码失败的原因,因此它说它无法将 GDAXI[0] 解析为 Date 对象。

如果要在quantmod中获取一行的名称,需要使用index函数,eg:

# Return all dates
index(GSPC)

您可能还想看看这个 related question