• You have a data sequence ๐ท๐‘Ž๐‘ก๐‘Ž, the Vector[1, 2, 3, 4, 5].
  • The window width ๐‘†๐‘๐‘Ž๐‘› of each subsequence is 3.
  • The function ๐น๐‘ข๐‘›๐‘ to be applied over subsequences of ๐ท๐‘Ž๐‘ก๐‘Ž is sum.
using RollingFunctions

๐ท๐‘Ž๐‘ก๐‘Ž = [1, 2, 3, 4, 5]
๐น๐‘ข๐‘›๐‘ = sum
๐‘†๐‘๐‘Ž๐‘› = 3

rolled = rolling(๐น๐‘ข๐‘›๐‘,๐ท๐‘Ž๐‘ก๐‘Ž, ๐‘†๐‘๐‘Ž๐‘›)


julia> rolled
3-element Vector{Int64}:
  6
  9
 12

#=
The first  windowed value is the ๐น๐‘ข๐‘›๐‘ (sum) of the first  ๐‘†๐‘๐‘Ž๐‘› (3) values in ๐ท๐‘Ž๐‘ก๐‘Ž.
The second windowed value is the ๐น๐‘ข๐‘›๐‘ (sum) of the second ๐‘†๐‘๐‘Ž๐‘› (3) values in ๐ท๐‘Ž๐‘ก๐‘Ž.
The third  windowed value is the ๐น๐‘ข๐‘›๐‘ (sum) of the third  ๐‘†๐‘๐‘Ž๐‘› (3) values in ๐ท๐‘Ž๐‘ก๐‘Ž.

There can be no fourth value as the third value used the fins entries in๐ท๐‘Ž๐‘ก๐‘Ž.
=#

julia> sum(๐ท๐‘Ž๐‘ก๐‘Ž[1:3]), sum(๐ท๐‘Ž๐‘ก๐‘Ž[2:4]), sum(๐ท๐‘Ž๐‘ก๐‘Ž[3:5])
(6, 9, 12)


If the width of each subsequence increases to 4..

๐‘†๐‘๐‘Ž๐‘› = 4
rolled = rolling(๐ท๐‘Ž๐‘ก๐‘Ž, ๐‘†๐‘๐‘Ž๐‘›, ๐’ฎ);

rolled
2-element Vector{Int64}:
 10
 14

Generally, with data that has r rows using a width of s results in r - s + 1 rows of values.

with matricies

#=

You have n data vectors of equal length (rowcount ๐“‡)
๐ท๐‘Ž๐‘ก๐‘Žโ‚ .. ๐ท๐‘Ž๐‘ก๐‘Žแตข .. ๐ท๐‘Ž๐‘ก๐‘Žโ‚™  collected as an ๐“‡ x ๐“ƒ matrix ๐‘€
you want to apply the same function (sum) 
to colum-wise triple row subsequences, successively

=#

using RollingFunctions

๐ท๐‘Ž๐‘ก๐‘Žโ‚ = [1, 2, 3, 4, 5]
๐ท๐‘Ž๐‘ก๐‘Žโ‚‚ = [5, 4, 3, 2, 1]
๐ท๐‘Ž๐‘ก๐‘Žโ‚ƒ = [1, 2, 3, 2, 1]

๐‘€ = hcat(๐ท๐‘Ž๐‘ก๐‘Žโ‚, ๐ท๐‘Ž๐‘ก๐‘Žโ‚‚, ๐ท๐‘Ž๐‘ก๐‘Žโ‚ƒ);

#=
julia> ๐‘€
5ร—3 Matrix{Int64}:
 1  5  1
 2  4  2
 3  3  3
 4  2  2
 5  1  1
=#

๐น๐‘ข๐‘›๐‘ = sum
๐‘†๐‘๐‘Ž๐‘› = 3

result = rolling(๐น๐‘ข๐‘›๐‘, ๐‘€, ๐‘†๐‘๐‘Ž๐‘›)

#=
julia> result
3ร—3 Matrix{Int64}:
  6  12  6
  9   9  7
 12   6  6
=#

multicolumn functions

#=

You have n data vectors of equal length (rowcount ๐“‡)
๐ท๐‘Ž๐‘ก๐‘Žโ‚ .. ๐ท๐‘Ž๐‘ก๐‘Žแตข .. ๐ท๐‘Ž๐‘ก๐‘Žโ‚™
you apply a function (StatsBase.cor) of n==2 arguments
to subsequences of width 3 (over successive triple rows)

=#

using RollingFunctions

๐ท๐‘Ž๐‘ก๐‘Žโ‚ = [1, 2, 3, 4, 5]
๐ท๐‘Ž๐‘ก๐‘Žโ‚‚ = [5, 4, 3, 2, 1]

๐น๐‘ข๐‘›๐‘ = cor
๐‘†๐‘๐‘Ž๐‘› = 3

result = rolling(๐น๐‘ข๐‘›๐‘,๐ท๐‘Ž๐‘ก๐‘Žโ‚,๐ท๐‘Ž๐‘ก๐‘Žโ‚‚, ๐‘†๐‘๐‘Ž๐‘›)
#=
3-element Vector{Float64}:
  -1.0
  -1.0
  -1.0
=#