[R] Split a time series

Achim Zeileis Achim.Zeileis at uibk.ac.at
Wed Jul 14 16:42:59 CEST 2010


On Wed, 14 Jul 2010, Megh Dal wrote:

> Hi all, can somebody help me to split a time series (zoo) object on monthwise. For example, suppose I have following time series object:
>
> library(zoo)
> dat1 <- zooreg(rnorm(300), start=as.Date("2009-01-01"), frequency=1)
>
>> From dat1, I want to create a list-object dat2 like:
>
> dat2[[1]] <- all observation for jan-2009
> dat2[[2]] <- all observation for feb-2009
>
> etc.

split(dat1, as.yearmon(time(dat1)))

seems to return what you want.
Z

> Thanks
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list