Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: xts get year or month for a certain row in a xts time series object

Tags:

r

xts

How can I get for example the year of the first or last entry in a xts time series object as a string? In this example of the AAPL time series?

require(quantmod)
getSymbols("AAPL")
like image 967
MichiZH Avatar asked Sep 06 '25 23:09

MichiZH


1 Answers

Year of first entry....

format(index(first(AAPL)),"%Y")

Year of last entry...

format(index(last(AAPL)),"%Y")
like image 155
h.l.m Avatar answered Sep 10 '25 11:09

h.l.m