How to remove repeated elements in a vector, similar to 'set' in Python

前端 未结 3 2105
忘了有多久
忘了有多久 2021-01-31 14:21

I have a vector with repeated elements, and would like to remove them so that each element appears only once.

In Python I could construct a Set from a vector to achieve

3条回答
  •  感情败类
    2021-01-31 15:22

    This does the same thing. Slower, but useful if you also want a logical vector of the duplicates:

    v[duplicated(v)]
    

提交回复
热议问题