1

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?

tonytonov
  • 25,060
  • 16
  • 82
  • 98
rm167
  • 1,185
  • 2
  • 10
  • 26
  • So you would like to get a list like this: [[1]] Jan 99 - Sep 99, [[2]] Oct 99 - Nov 99, [[3]] Dec 99 - Sep 00, [[4]] Oct 00 - Nov 00, etc, correct? – tonytonov Apr 14 '14 at 13:40
  • It also serves my purpose. But I would prefer if I can get it like [[1]] Sep 99 -Dec 99, [[2]] Sep 00 -Dec 00 and so on. Thank you – rm167 Apr 15 '14 at 14:03

1 Answers1

1

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.

Community
  • 1
  • 1
tonytonov
  • 25,060
  • 16
  • 82
  • 98