I have the following table of group IDs (GroupNum) with a list of values that they are associated with (NPI_list):
df1 <- data.frame(GroupNum=c(41,224,1032,2754,3907,4107),
NPI_list=c('1740411552,1932387479','1710112156,1841438280',
'1629405113,1942433891','1629405113,1992083588',
'1710112156,1841438280','1740411552,1932387479'),
stringsAsFactors = F)
There are instances where there are common elements between list. I need to consolidate groups with common values within each of their respective GroupNum IDs such that I get an end product similar to the following
df2 <- data.frame(GroupNum=c('41,4107','224,3907','1032,2754'),
NPI_list=c('1740411552,1932387479','1710112156,1841438280','1629405113,1992083588,1942433891'),
stringsAsFactors = F)
I have been told that there is a way to determine if there are common elements between list via python but I only have experience with R. I have tried a similar dplyr solution to that of Duck below but it still groups NPI_list and I need to be able to compare the individual elements within each list to that of all other list and combine the lists if there is a single match.
Any advice would be helpful. I am suspecting that I will need to use some sort of for loop.