In Julia DataFrame, how can I do a group by and use the value of the next rows?
For example:
using DataFrames, DataFramesMeta
df = DataFrame(grp=["one", "one", "two", "two", "three"], val=[1, 2, 3, 4, 5])
# Row │ grp val
# │ String Int64
#─────┼───────────────
# 1 │ one 1
# 2 │ one 2
# 3 │ two 3
# 4 │ two 4
# 5 │ three 5
@combine(groupby(df, :grp),
count = length(:val),
first_val = first(:val),
#next_val = next(:val)
)
#3×3 DataFrame
# Row │ grp count first_val
# │ String Int64 Int64
#─────┼──────────────────────────
# 1 │ one 2 1
# 2 │ two 2 3
# 3 │ three 1 5
# I would like to obtain:
# Row │ grp count first_val next_val
# │ String Int64 Int64
#─────┼──────────────────────────
# 1 │ one 2 1 2
# 2 │ two 2 3 4
# 3 │ three 1 5 NA