JuliaData / SplitApplyCombine.jl

Split-apply-combine strategies for Julia
Other
144 stars 15 forks source link

How exactly grouping work? #56

Closed ghost closed 1 year ago

ghost commented 1 year ago

I have a set of 4-tuples and would like to group them based on their third position and an extra condition on forth position. For instance:

A = [(1,5,2,5), (,12,5,9,6), (7,5,2,6), (11,5,2,5), (8,5,9,6), (3,5,3,6), (7,5,9,6), (1,5,3,6), (1,5,3,8), (2,5,3,6), (1,5,3,7), (1,4,3,6), (8,5,9,7), (3,5,3,8), (7,2,9,6)]
Third = [2,9,3 ] 
forth_con = [5,6]
andyferris commented 1 year ago

So to group by the third element you could use group(x -> x[3], A).

Depending on what you want, you could group by a combination of the 3rd/4th keys with group(x -> (x[3], x[4]), A) or you could do it nested like group.(x -> x[4], group(x -> x[3], A)). (Oh how I do like that Dictionary can broadcast!)

Lastly, Discourse, Slack or Zulip might be better places to go for Q&A - you're likely to get faster responses, and GitHub is more for development issues.