Andrew Bannerman
Andrew Bannerman

Reputation: 1305

Rolling windows using for loops

So I am coding up rolling windows in Julia.

There is one function I wish to replicate. The desired result I achieved was using R, zoo package, rollapply with the align="center" default.

So in order to re-create a centered rolling window I looked at the zoo source code for roll apply:

 ix <- switch(align,
      "left" = { 1:(n-k+1) },
      "center" = { floor((1+k)/2):ceiling(n-k/2) },
      "right" = { k:n })

In understanding how this translate to a for loop in Julia....

I have a for loop with a rolling window that may be set like this:

n = 20
[i-n+1:i]

or I can fix the starting point

n=20
[1:i+n]

I thought this was all there was to rolling windows.

How would one code up a centered window? I sifted through the R source code but its not really hitting home.

Upvotes: 0

Views: 384

Answers (1)

Michael K. Borregaard
Michael K. Borregaard

Reputation: 8044

Like most other things in Julia, the functionality is in packages. You could check out https://github.com/JeffreySarnoff/RollingFunctions.jl . A more general multidimensional implementation is in https://github.com/JuliaImages/ImageFiltering.jl

Upvotes: 2

Related Questions