Hi, it is a feature that I also struggled to find a solution so I needed to customize some a code to make it work as I want.
So here is my solution. I have found a very useful code on GitHub : https://github.com/hms-dbmi/UpSetR/issues/85#issuecomment-415480954
I adapted it to make it more readable so here is my final code :
overlapGroups <- function (listInput, sort = TRUE) {
listInputmat <- fromList(listInput) == 1
listInputunique <- unique(listInputmat)
grouplist <- list()
for (i in 1:nrow(listInputunique)) {
currentRow <- listInputunique[i,]
myelements <- which(apply(listInputmat,1,function(x) all(x == currentRow)))
attr(myelements, "groups") <- currentRow
grouplist[[paste(colnames(listInputunique)[currentRow], collapse = ":")]] <- myelements
myelements
}
if (sort) {
grouplist <- grouplist[order(sapply(grouplist, function(x) length(x)), decreasing = TRUE)]
}
attr(grouplist, "elements") <- unique(unlist(listInput))
return(grouplist)
}
Intersection=overlapGroups(yourlist)
purrr::map(Intersection, ~ attr(Intersection, "elements")[.x] )
Example :
yourlist=list(A=c("a","b","c","d"),B=c("a","c","e","f"))
Intersection=overlapGroups(yourlist)
purrr::map(Intersection, ~ attr(Intersection, "elements")[.x] )
$`A:B`
[1] "a" "c"
$A
[1] "b" "d"
$B
[1] "e" "f"