How to get common values between two multi sets? I am working in R. I have two vectors; A and B of lengths 5913 and 3733 respectively (with entries are repeated). I want to extract those values (with repetitions) that are present in both A and B. 
I have done (A %in% B) (lets call it C) and (B %in% A) (lets call it D). 
The length of C is 3906 and that of D is 3607 (so 2007 elements in A are not in B and 126 elements in B are not in A). 

But How do I find the common values ? I don't think I can use intersect() method as it expects vectors with no duplicate values. I have many many repetitions. 

Note: Due to the length of these vectors, I couldn't mention them here. 

Any help would be greatly appreciated. 

Thanks
Since you have multiple repetitions in A and B, and these two vectors are of different lengths (5913 and 3733), it is expected that vector C and D are of different size. However, C and D might contain the same unique elements.

Let's take the example proposed by Biswajit Banerjee:

A = c(1,1,2,2,3,3,4,4,5,5,6,6,9,11,15,17,19,19)
B = c(1,2,2,2,3,3,3,4,5,6,7,8,8,8)

C= A[(A %in% B)]
D = B[(B %in% A)]

all(unique(C) == unique(D))
TRUE


You could verify that your vectors C and D of length 2007 and 126 contains the same unique values. Does it solve your problem ?