Question

I am using xts package to split the time series in to monthly, yearly, etc. The code I am using is

obsm<-split(obs, f = 'months', drop=FALSE, k = 1)

where 'obs' being the whole time series with four year data (1999-2012). I can also split the series in to years, quarters, weeks. But is there anyway where I can split the series for the time period I want. for eg every year from September to November?

Was it helpful?

Solution

Here's what you can do: first subset only the months you need, then split them by year. Using dummy data:

x <- as.xts(zooreg(1:2000, start = as.Date("2000-01-01")))
split(x[.indexmon(x) %in% 8:11], f="years")

The idea with .indexmon is given here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top