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

前端 未结 3 2085
忘了有多久
忘了有多久 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:21

    You can check out unique function.

     > v = c(1, 1, 5, 5, 2, 2, 6, 6, 1, 3)
     > unique(v)
     [1] 1 5 2 6 3
    

提交回复
热议问题