PumasAI / SummaryTables.jl

A Julia package for creating publication-ready summary tables in HTML, docx, LaTeX and Typst
https://pumasai.github.io/SummaryTables.jl/
MIT License
59 stars 1 forks source link

Sorting by column group #22

Closed andreasnoack closed 2 weeks ago

andreasnoack commented 2 weeks ago

It would be nice if also the column group would be sorted. See this example

julia> df = DataFrame(value = ones(6), A = ['c', 'c', 'c', 'b', 'b', 'a'], B = [4, 2, 8, 2, 4, 4])
6×3 DataFrame
 Row │ value    A     B     
     │ Float64  Char  Int64 
─────┼──────────────────────
   1 │     1.0  c         4
   2 │     1.0  c         2
   3 │     1.0  c         8
   4 │     1.0  b         2
   5 │     1.0  b         4
   6 │     1.0  a         4

julia> summarytable(df, :value, rows = :A, cols = :B, summary = [sum])

which gives

Skærmbillede 2024-09-15 kl  20 53 23
jkrumbiegel commented 2 weeks ago

Yeah I think this is actually a logic bug, the table is sorted by all groups at once, but then if the table is not fully balanced (some group combinations are missing) the in-column order of the latter factors can be different than if it were to be sorted on its own. I guess each column needs to be sorted on its own and the placement logic changed to avoid this. Good MWE