Get date column from xts object

I used getSymbols to get the stock data, and it returned something like this:

 > require(quantmod) > getSymbols(AAPL) > head(AAPL) AAPL.Open AAPL.High AAPL.Low AAPL.Close 2007-01-03 86.29 86.58 81.90 83.80 2007-01-04 84.05 85.95 83.82 85.66 2007-01-05 85.77 86.20 84.40 85.05 2007-01-08 85.96 86.53 85.28 85.47 2007-01-09 86.45 92.98 85.15 92.57 2007-01-10 94.75 97.80 93.45 97.00 > str(AAPL) An 'xts' object on 2007-01-03/2015-02-23 containing: Data: num [1:2049, 1:6] 86.3 84 85.8 86 86.5 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:6] "AAPL.Open" "AAPL.High" "AAPL.Low" "AAPL.Close" ... Indexed by objects of class: [Date] TZ: UTC xts Attributes: List of 2 $ src : chr "yahoo" $ updated: POSIXct[1:1], format: "2015-02-24 17:12:45" 

How to get dates? It seems dates are not in the data. AAPL[1,1] returns:

  AAPL.Open 2009-01-02 85.88 

And rownames(AAPL) returns NULL . What's going on here? How are dates related to the rest of the object? How to get dates?

+6
source share
1 answer

getSymbols by default does not return data.frame ; it returns an xts object. Xts objects do not have line names. They have an index attribute that can be accessed using the index function.

+7
source

Source: https://habr.com/ru/post/982532/


All Articles