Not able to use lag and lead function

Hi i just tried to sun a simple exmaple which is given here
https://stackoverflow.com/questions/61038354/create-lag-lead-time-series-with-by-groups-in-julia

using DataFrames, ShiftedArrays

df1 = DataFrame(var1=["a","a","a","a","b","b","b","b"],
                                    var2=[0,1,2,3,0,1,2,3]);
by(df1, :var1, var2_l2 = :var2 => Base.Fix2(lag, 2))

but it resulted in below error

julia> by(df1, :var1, var2_l2 = :var2 => Base.Fix2(lag, 2))
ERROR: UndefVarError: lag not defined
Stacktrace:
 [1] top-level scope
   @ ~/data/code/NICU_DEC_2022/data_wrangling.jl:105

Is there any other way to get lag and lead values of a column.
I used to use below code earler, but its not working now

transform!(groupby(df,:ID),:TIME => lag, :TIME => lead)

Thanks in advance

The function names just aren’t imported in the latest ShiftedArrays version, so you need to either qualify ShiftedArrays.lead or import them explicitly:

julia> using DataFrames; import ShiftedArrays: lead, lag

julia> transform(DataFrame(TIME = rand(5)), :TIME .=> [lag, lead])
5Γ—3 DataFrame
 Row β”‚ TIME      TIME_lag        TIME_lead      
     β”‚ Float64   Float64?        Float64?       
─────┼──────────────────────────────────────────
   1 β”‚ 0.543515  missing               0.745711
   2 β”‚ 0.745711        0.543515        0.181031
   3 β”‚ 0.181031        0.745711        0.765985
   4 β”‚ 0.765985        0.181031        0.201351
   5 β”‚ 0.201351        0.765985  missing        
5 Likes