dwcecil
dwcecil

Reputation: 31

Extract the year-month-day from xts

I have retrieved an xts via the quantmod package for the S&P500, and specified a certain date range:

library(quantmod)
getSymbols("SP500", src="FRED")

SP500.noNA <- SP500[-which(is.na(SP500))]

SP500.start <- match(as.Date("2018-12-13"), index(SP500.noNA)) - 30
SP500.end <- match(as.Date("2018-12-27"), index(SP500.noNA))
SP500.period <- SP500.noNA[SP500.start:SP500.end]

I want to extract from the xts 'SP500.period' the vector of dates. Much of the documentation for xts is about about how to filter the indices on certain date ranges/sequences, but how do I just retrieve the date information?

Upvotes: 1

Views: 417

Answers (1)

akrun
akrun

Reputation: 887048

We can use index

index(SP500.period)

Upvotes: 2

Related Questions