Skip to content

request - running lag function #177

Description

@lincolnhannah

Sample function shown below for 1-dimension case.
General case would be more complex.
Useful for running differences.

using AxisKeys, Dates

data    = 1:10                             |> collect
date    = Date(2000,1,1):Date(2000,1,10)   |> collect 
ka      = KeyedArray( data; date,   )


function lagwise( ka::KeyedArray, dim::Symbol, n::Int, data_func::Function, dim_func::Function )

    data  = data_func.(   ka.data.data[1+n:end],      ka.data.data[1:end-n]       )

    dimV  = dim_func.(    axiskeys(ka,dim)[1:end-n],  axiskeys(ka,dim)[1+n:end]   )

    KeyedArray( data, dimV )

end


lagwise( ka, :date, 2, -, tuple )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions