[R] Difference between two time series

R. Michael Weylandt michael.weylandt at gmail.com
Tue Nov 15 21:43:09 CET 2011


It's not clear what it means for the differences to be "of increasing
order" but if you simply mean the differences are increasing, perhaps
something like this will work:

library(caTools)
X = cumsum( 2*(runif(5e4) > 0.5) - 1) # Create a random Walk
Y = runmean(X, 30, endrule = "mean", align = "right")

D = X - Y # Create the difference series:

# Now we need to find the ranges of increasing: to do this, we can just lag D

sign(D - c(0, D[1:(length(D)-1)]))

If you want to find the length of each run or to find runs of a
certain length, try rle().

Michael

On Tue, Nov 15, 2011 at 2:18 PM, Sarwarul Chy <sarwar.shabuj at gmail.com> wrote:
> Hello,
>
> Can you please help me with this? I am also stack in the same problem.
>
> Sam
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Difference-between-two-time-series-tp819843p4073800.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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