Thank you Cédric !

Yes it works with an extra column a_1 :


julia> df
8x4 DataFrames.DataFrame
│ Row │ a │ b │ c         │ sum        │
┝━━━━━┿━━━┿━━━┿━━━━━━━━━━━┿━━━━━━━━━━━━┥
│ 1   │ 1 │ 2 │ 2.28386   │ -0.0551961 │
│ 2   │ 2 │ 1 │ 0.174953  │ 0.472804   │
│ 3   │ 3 │ 2 │ -1.31137  │ 0.994803   │
│ 4   │ 4 │ 1 │ 0.305978  │ 0.580371   │
│ 5   │ 1 │ 2 │ -0.725308 │ 1.19441    │
│ 6   │ 2 │ 1 │ 0.095797  │ 1.19544    │
│ 7   │ 3 │ 2 │ -0.481912 │ 0.284116   │
│ 8   │ 4 │ 1 │ 0.811624  │ 1.23245    │

julia> by(df, :a) do subdf
          subdf[indmax(subdf[:sum]), :]
       end
4x5 DataFrames.DataFrame
│ Row │ a │ a_1 │ b │ c         │ sum      │
┝━━━━━┿━━━┿━━━━━┿━━━┿━━━━━━━━━━━┿━━━━━━━━━━┥
│ 1   │ 1 │ 1   │ 2 │ -0.725308 │ 1.19441  │
│ 2   │ 2 │ 2   │ 1 │ 0.095797  │ 1.19544  │
│ 3   │ 3 │ 3   │ 2 │ -1.31137  │ 0.994803 │
│ 4   │ 4 │ 4   │ 1 │ 0.811624  │ 1.23245  │



Reply via email to