[R] Rolling window difference for zoo time series

Achim Zeileis Ach|m@Ze||e|@ @end|ng |rom u|bk@@c@@t
Tue Apr 24 22:02:59 CEST 2018


On Tue, 24 Apr 2018, Eric Berger wrote:

> Zoo_TS/lag(Zoo_TS) - 1

Or:

diff(Zoo_TS, arithmetic = FALSE) - 1

>
> On Tue, Apr 24, 2018 at 9:29 PM, Christofer Bogaso <
> bogaso.christofer using gmail.com> wrote:
>
>> Hi,
>>
>> I have a 'zoo' time series as below :
>>
>> Zoo_TS = zoo(5:1, as.Date(Sys.time())+0:4)
>>
>> Now I want to calculate First order difference of order 1, rolling
>> window basis i.e.
>>
>> (Zoo_TS[2] - Zoo_TS[1] ) / Zoo_TS[1]
>> (Zoo_TS[3] - Zoo_TS[2] ) / Zoo_TS[2]
>> .....
>>
>> Is there any direct function available to achieve this?
>>
>> Thanks,
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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