I'd like to remove all items that appear more than once in a vector. Currently, I'm using duplicated() both forwards and backward (using the fromLast parameter).
Is there a more efficient way to execute this in R? The solution below is simple enough, but it seems inefficient to execute the duplicate search twice. Perhaps a counting-based method using an additional data structure would be better?
Example:
d <- c(1,2,3,4,1,5,6,4,2,1)
d[!(duplicated(d) | duplicated(d, fromLast=TRUE))]
#[1] 3 5 6
