For example, I have 5 vectors in a list:
A <- c(1,2,3,4,5)
B <- c(1,2,3,4,5,6)
C <- c(5,6,7,8,9)
D <- c(8,9)
In reality I have 100s of these vectors but I only gave 5 vectors for reproducibility. My goal is to:
- Identify the unique elements coming from the vectors. For example,
vector Ashouldn't return anything because all of its elements are part ofvector B, howevervector Bdoes contribute with an extra unique element and that is6.Vector Cshould give me7,8,9sincec(5,6)were already included invector B.Vector Dshould return nothing because all of its elements are part of C - recognize which element is unique from which vector
- Find which vectors are subsets of other bigger vectors. For example,
vector Dis a subset ofCandvector Ais a subset ofvector B.
So far the only solution I've found was:
Reduce(setdiff, list("my_vectors"))
But it doesn't allow me to recognize which element is unique from which vector. For example, Reduce(setdiff, list(A,B)) would return 6, but I would have no idea where the 6 came from ( A or B)?
My difficulty is in this being a large scale problem, I don't have 5 vectors only, I have 100s of them so I can't figure out a sustainable solution. Any tips are appreciated.
Edit: my vectors are in a list