你可以用setdiff它:
R> v <- c(1,1,2,2,3,4,5)
R> setdiff(v, v[duplicated(v)])
[1] 3 4 5
Run Code Online (Sandbox Code Playgroud)
你可以使用count从plyr包来算项目的出现次数,并删除谁发生不止一次所有.
library(plyr)
l = c(1,2,3,3,4,5,6,6,7)
count_l = count(l)
x freq
1 1 1
2 2 1
3 3 2
4 4 1
5 5 1
6 6 2
7 7 1
l[!l %in% with(count_l, x[freq > 1])]
[1] 1 2 4 5 7
Run Code Online (Sandbox Code Playgroud)
注意!,这意味着NOT.你当然把它放在一个oneliner上:
l[!l %in% with(count(l), x[freq > 1])]
Run Code Online (Sandbox Code Playgroud)