如何删除向量中的重复元素,类似于Python中的“设置" [英] How to remove repeated elements in a vector, similar to 'set' in Python
本文介绍了如何删除向量中的重复元素,类似于Python中的“设置"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含重复元素的向量,并且想删除它们,以便每个元素仅出现一次.
I have a vector with repeated elements, and would like to remove them so that each element appears only once.
在Python中,我可以从向量构造 Set
来实现这个,但是我该如何在R中做到这一点?
In Python I could construct a Set
from a vector to achieve this, but how can I do this in R?
推荐答案
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
这篇关于如何删除向量中的重复元素,类似于Python中的“设置"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文