Is there any simple way in R to make multi-level (ie, “bagged”) differences similar to setdiff() , but preserving the order and multiplicity in the input vectors?
For example, suppose x <- c(1,2,2,3,1,5,4,4,5,3) and y <- c(2,1,5,5) . I am looking for a function bagdiff() such that bagdiff(x,y) is c(2,3,1,4,4,3) , that is, the first occurrences of the elements y in x were removed with multiplicity.
(In my real problem, I will not care about the output order, so it is only important that the multiplicity is correct, but the general ordered case is really worth solving.)
source share