MichiZH
MichiZH

Reputation: 5807

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

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")

Upvotes: 4

Views: 3651

Answers (1)

h.l.m
h.l.m

Reputation: 13465

Year of first entry....

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

Year of last entry...

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

Upvotes: 4

Related Questions