# Grouping by Split, apply, combine

**URL:** https://discourse.julialang.org/t/grouping-by-split-apply-combine/84417
**Category:** General Usage
**Tags:** question, package, tuple, splitapplycombine
**Created:** [July 18, 2022, 5:21pm UTC](https://discourse.julialang.org/t/grouping-by-split-apply-combine/84417 "2022-07-18T17:21:23Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [July 19, 2022, 10:06am UTC](https://discourse.julialang.org/t/grouping-by-split-apply-combine/84417/10 "2022-07-19T10:06:48Z")

</div>

@Optimization, please check annotated code below, where the input was sligthly modified to try removing some ambiguity in the problem statement.

```julia
using SplitApplyCombine

A = [(1,5,2,5), (11,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)]
D = group(t -> t[3], A) # groups tuples by their 3rd element
b = (11, 8, 3) # tuple for filtering the last 3 groups computed, one value per group

[k => filter(x -> x[1] == v, d) for (v, (k,d)) in zip(b, pairs(D))] # matches first element of each tuple

3-element Vector{Pair{Int64, Vector{NTuple{4, Int64}}}}:
 2 => [(11, 5, 2, 5)]
 9 => [(8, 5, 9, 6)]
 3 => [(3, 5, 3, 6)]

```

---

_[View the full topic](https://discourse.julialang.org/t/grouping-by-split-apply-combine/84417)._
