I have a df such as :
df1
Nb Groups_subgroups
A 1_Cluster17972,1_Cluster2653,1_Cluster3900,2_Cluster12159,1_Cluster1798,1_Cluster17493
B 7_Cluster13022,1_Cluster4976
C 2_Cluster27505
D 7_Cluster25561,23_Cluster25561
E 1_Cluster23500
And another df2 such as :
Groups Subgroups
Cluster17972 1
Cluster17972 2
Cluster2653 1
Cluster3900 1
Cluster12159 2
Cluster12159 3
Cluster1798 1
Cluster17493 1
Cluster00001 1
Cluster00001 2
Cluster13022 7
Cluster4976 1
Cluster27505 2
Cluster25561 7
Cluster25561 23
Cluster23500 1
And I would like to merge df1$Groups_subgroups with df2$Groups and df2$Subgroups columns and get a result such as :
Groups Subgroups Nb
Cluster17972 1 A
Cluster17972 2 NA
Cluster2653 1 A
Cluster3900 1 A
Cluster12159 2 A
Cluster12159 3 NA
Cluster1798 1 A
Cluster17493 1 A
Cluster00001 1 NA
Cluster00001 2 NA
Cluster13022 7 B
Cluster4976 1 B
Cluster27505 2 C
Cluster25561 7 D
Cluster25561 23 D
Cluster23500 1 E
Does someone have an idea ? Here are the two df in dput format :
df1
structure(list(Nb = c("A", "B", "C", "D", "E"), Groups_subgroups = c("1_Cluster17972,1_Cluster2653,1_Cluster3900,2_Cluster12159,1_Cluster1798,1_Cluster17493",
"7_Cluster13022,1_Cluster4976", "2_Cluster27505", "7_Cluster25561,23_Cluster25561",
"1_Cluster23500")), class = "data.frame", row.names = c(NA, -5L
))
df2
structure(list(Groups = c("Cluster17972", "Cluster17972", "Cluster2653",
"Cluster3900", "Cluster12159", "Cluster12159", "Cluster1798",
"Cluster17493", "Cluster00001", "Cluster00001", "Cluster13022",
"Cluster4976", "Cluster27505", "Cluster25561", "Cluster25561",
"Cluster23500"), Subgroups = c(1, 2, 1, 1, 2, 3, 1, 1, 1, 2,
7, 1, 2, 7, 23, 1)), class = "data.frame", row.names = c(NA,
-16L))