[R] Calculate a function repeatedly over sections of a ts object

R. Michael Weylandt michael.weylandt at gmail.com
Thu Jan 26 22:00:21 CET 2012


I'm not sure if it's easily doable with a ts class, but the rollapply
function in the zoo package will do this easily. (Also, I find zoo to
be a much more natural time-series workflow than ts so it might make
the rest of your life easier as well)

Michael

On Thu, Jan 26, 2012 at 2:24 PM, Jorge Molinos <JGARCIAM at tcd.ie> wrote:
>
> Hi,
>
> I want to apply a function (in my case SDF; package “sapa”) repeatedly over discrete sections of a daily time series object by sliding a time window of constant length (e.g. 10 consecutive years or 1825 days) over the entire ts at increments of 1 time unit (e.g. 1 year or 365 days). So for example, the first SDF would be calculated for the daily values of my variable recorded between years 1 to 5, SDF2 to those for years 2 to 6 and so on until the total length of the series is covered. How can I implement this into a R script? Any help is much appreciated.
>
> Jorge
> ______________________________________________
> 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