This looks easy enough, but I keep bumping my head.
I have the numeric vector v1
v1 <- c(1,1,3,5,7,7) And I have a numeric vector v2. v2 is always a subset of v1.
I want to remove the all elements from v2 from v1, but only one (and exaclty one) v1 element per v2 element.
desired output
if v2 <- c(3,5) I want to keep c(1,1,7,7) from v1. This one is easy using v1[-match(v2, v1)].
if v2 <- c(1,7) I want to keep c(1,3,5,7) from v1. also, v1[-match(v2, v1)] does the trick.
if v2 <- c(1,1) I want to keep c(3,5,7,7) from v1. Now v1[-match(v2, v1)] returns [1] 1 3 5 7 7.. Not what I want.