2
votes

Is there a built-in lagged operator function in julia? I.e., a function of the form:

lagop(op,array,offset)

that returns something like

[array[i + offset] (op) array[i] for i in 1:length(array)-offset]

For successive differences, there is the diff function. For sums either of the following works:

x = collect(1:10)
x[1:end-1]+x[2:end]
[x[i]+x[i+1] for i in 1:length(x)-1]

Is there a general function to accomplish tasks like this?

1
lagop(op,array,offset) = [op(array[i + offset], array[i]) for i in 1:length(array)-offset] is not enough? - Liso
@Liso It's definitely implementable, but in some scenarios these kinds of operations are ubiquitous and such a function saves time/increases readability. E.g., the rollapply function in the R package zoo. - Richard Border

1 Answers

1
votes

You mention the zoo library in R, which is for time series. If that's your use case, you will find lag implemented in TimeSeries.jl: http://timeseriesjl.readthedocs.io/en/latest/apply.html#lag It may not be exactly what you want, though.