Search code examples
rjoindplyruniqueintersection

R- unique and common items across each of three vectors (or data frame columns) for venn diagram


I am trying to compare three different vectors of different length for unique and overlapping elements using R. Each of the elements contains a string ("label" of interest) for further analysis via a venn diagram. No duplicate elements exist in any of the string.

Can somebody please suggest a simple way to select all unique and common elements for each vector - "ad", "ld", and "md" in the example below?

ad<-c("abc 1", "cd4", "efg9", "hij 2", "kl 2N", "mno1", "pq22", "rs5", 
"wv92", "da2")
ld<-c("cd4", "hij 2", "xy3", "xyz 2", "vw9", "pq22", "lm3", "p3", "da2")
md<-c("pq22", "da2", "ef44", "hi9", "q1", "r 44")

Thank you in anticipation.


Solution

  • Thank you @user20650 for the answer to above question. The following code is the solution:

    VennDiagram::get.venn.partitions(list(ad=ad, ld=ld, md=md))
    grid.newpage()
    grid::grid.draw(VennDiagram::venn.diagram(list(ad=ad, ld=ld, md=md), NULL))