I have a set of 6 vectors of different lengths (colnames: tp1-tp6). Looks something like this:
tp1 tp2 tp3 tp4 tp5 tp6
K06167 K14521 K17095 K21805 K03238 K18213
K07376 K17095 K01424 K13116 K03283 K14521
K03347 K14521 K14319 K00799 K08901 K01756
K20179 K01693 K01682 K03283 K02716 K03238
K03527 K02882 K01414 K01693 K08907 K01850
K08901 K02912 K00940 K14319 K00411 K01768
K11481 K02868 K04043 K14835 K01414 K15335
K02716 K14835 K12606 K19371 K00963 K12818
K03545 K14766 K09550 K04043 K01749 K02975
K08907 K00602 K15437 K09550 K03116 K03002
K15470 K10798 K03456 K03687 K09550 K17679
K16465 K14823 K18059 K03456 K08738 K13116
K03116 K00940 K03115 K18534 K08907 K14521
K08738 K16474 K15502 K03495 K03687 K01937
K08907 K19371 K00026 K13100 K08907 K03002
.
.
.
I would like to create a list that contains all of the respective Kvalues that match between every possible combination of the 6 vectors. For instance, for the combination of tp2 and tp3, I want to find all of the values that the two vectors share in common, but don't appear in any of the other vectors (tp1, tp4, tp5, tp6). In this case it would be K00940. Is this possible with vectors of different lengths in R?
There was a similar question asked in
Finding all possible combinations of vector intersections?
and I have tried one of the codes given in the answers. While the code does give me all possible combinations and their respective values in a large list, it does not factor in that I only want unique intersections between the different vectors. For instance, the combination of tp2 and tp3 yielded me all possible values that the two vectors shared in common, but included values that were present in the other vectors that were also present in tp2 and tp3. I just want the unique values that only tp2 and tp3 have in common.
veclist <- list(tp1, tp2, tp3, tp4, tp5, tp6)
combos <- Reduce(c,lapply(1:length(veclist), function(x) combn(1:length(veclist),x,simplify=FALSE)))
CKUP_combos <- lapply(combos, function(x) Reduce(intersect, veclist[x]) )