I specifically began to think in this problem, trying to get values from a vector that was not repeated. uniquenot suitable (to the point that I could get from the documentation), because it gives you duplicate elements, but only once. duplicatedhas the same problem as it gives you FALSE on the first detection of a value that is duplicated. This was my workaround.
> d=c(1,2,4,3,4,6,7,8,5,10,3)
> setdiff(d,unique(d[duplicated(d)]))
[1] 1 2 6 7 8 5 10
Below is a more general approach
> table(d)->g
> as.numeric(names(g[g==1]))
[1] 1 2 5 6 7 8 10
which we can generalize to a different value than 1. But I find this solution a little awkward, turning strings into numbers. Is there a better or easier way to get this vector?
source
share