# R function \`duplicated\`

**URL:** <https://discourse.julialang.org/t/r-function-duplicated/91707>\
**Category:** General Usage\
**Tags:** function\
**Created:** [December 15, 2022, 5:29pm UTC](https://discourse.julialang.org/t/r-function-duplicated/91707 "2022-12-15T17:29:40Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 15, 2022, 6:23pm UTC](https://discourse.julialang.org/t/r-function-duplicated/91707/9 "2022-12-15T18:23:12Z")

</div>

> [@\_stla](#):
>
> To remove the duplicates of a vector you can do `v[!duplicated(v)]`.

Couldn’t you do

```julia
i = unique(j -> v[j], eachindex(v))
v[i]

```

for this purpose? This gives you an index array that you could re-use to extract corresponding slices of other arrays too.

See also the discussions at [Return index vectors from unique · Issue #1845 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/1845) and  
[Is there a function similar to numpy unique with inverse? - #6 by stevengj](https://discourse.julialang.org/t/is-there-a-function-similar-to-numpy-unique-with-inverse/80949/6)

---

_[View the full topic](https://discourse.julialang.org/t/r-function-duplicated/91707)._
