5.6 Data Summaries

Similar to the combine DataFrames.jl function (Section 4.8), DataFramesMeta.jl has a @combine macro.

@combine leftjoined :mean_grade_2020 = mean(:grade_2020)
mean_grade_2020
4.625

@combine also supports multiple operations inside a begin ... end statement:

@combine leftjoined begin
    :mean_grade_2020 = mean(:grade_2020)
    :mean_grade_2021 = mean(:grade_2021)
end
mean_grade_2020 mean_grade_2021
4.625 6.375

Most of the time we would use @combine in a grouped dataframe by pairing it with groupby:

gdf = groupby(leftjoined, :name)
@combine gdf begin
    :mean_grade_2020 = mean(:grade_2020)
    :mean_grade_2021 = mean(:grade_2021)
end
name mean_grade_2020 mean_grade_2021
Sally 1.0 9.5
Hank 4.0 6.0
Bob 5.0 5.0
Alice 8.5 5.0


Support this project
CC BY-NC-SA 4.0 Jose Storopoli, Rik Huijzer, Lazaro Alonso