# Collapse duplicate rows in Julia matrix

**URL:** <https://discourse.julialang.org/t/collapse-duplicate-rows-in-julia-matrix/113817>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 3, 2024, 9:41pm UTC](https://discourse.julialang.org/t/collapse-duplicate-rows-in-julia-matrix/113817 "2024-05-03T21:41:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santiago\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_lopez/32/46298_2.png) [@Santiago\_Lopez](https://discourse.julialang.org/u/Santiago_Lopez)\
**Post date:** [May 3, 2024, 9:41pm UTC](https://discourse.julialang.org/t/collapse-duplicate-rows-in-julia-matrix/113817/1 "2024-05-03T21:41:32Z")

</div>

I have a matrix `U = vcat(s, e, p)` of the form

```julia
3167×2 Matrix{Int64}:
    1 1
    1 1
    1 1
    1 1
    1 2
    1 2
    1 2
    1 3
    1 3
    1 3
    3 2
    3 2
    3 3
    ⋮  
  962 5
  962 5
  962 5
  962 5
  962 5
 1007 5
 1009 5
 1009 5
 1009 5
 1009 5
 1009 5
 1045 2

```

where `s`, `e`, `p` are matrices of two columns themselves.

I want an equivalent of the `unique` function but for the rows, so that I obtain a matrix `U'` whose rows are the rows of `U` but without any duplicates. How can this be done?

---

<div class="post-metadata">

**Author:** ![junder873](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@junder873](https://discourse.julialang.org/u/junder873)\
**Post date:** [May 3, 2024, 9:43pm UTC](https://discourse.julialang.org/t/collapse-duplicate-rows-in-julia-matrix/113817/2 "2024-05-03T21:43:25Z")

</div>

Would `unique(m; dims=1)` work?

---

<div class="post-metadata">

**Author:** ![Santiago\_Lopez](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_lopez/32/46298_2.png) [@Santiago\_Lopez](https://discourse.julialang.org/u/Santiago_Lopez)\
**Post date:** [May 3, 2024, 9:45pm UTC](https://discourse.julialang.org/t/collapse-duplicate-rows-in-julia-matrix/113817/3 "2024-05-03T21:45:21Z")

</div>

Works. Thanks!
