Search code examples
rquantmod

Retreive row name from quantmod XTS file


I'm using the quantmod::getsymbols function to retreive the stock index data for yahoo finance (as showed in the picture, it's called GDAXI.xts)

Now I want to access the date to the left, but this column isn't in the GDAXI file. How can I access the date? I tried different ways and couldn't figure it out, last time it worked when I tried d1.ts=GDAX[,0], but that's not working here.

Can anybody tell me why? Thank you very much in advance.

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]

Solution

  • I'm not familiar with R or quantmod but it looks to me like what you want to do is get the name of the row, not any column data, which is probably why your code is failing, hence it saying that it can't parse GDAXI[,0] as a Date object.

    If you want to get a name of a row in quantmod, you need to use the index function, eg:

    # Return all dates
    index(GSPC)
    

    You may also want to take a look at this related question.