Hello I need to merge two data frames. The relevant ID columns of the two data frames contain comma-separated lists of IDs (as string).
For example those two data frames should be merged:
ID value
"abc,def,ghi" 5
"jkl" 8
"stu,xyz" 2
ID value
"def,xyz" 7
"klm" 6
"opq,stu" 9
My matching criterion would be positive if any of the individual ids in one ID-list is also present in the other. So the merged data frame should look like (for a left-join like merge):
ID value.Data.frame.1 value.Data.frame.2
"def,xyz" 5 7
"jkl" 8 NA
"stu,xyz" 2 9
"stu,xyz" 2 7
(My real data actually has more than one value column in the data frames.) Usually for the merge I would do something like:
merge(data.frame1, data.frame2, by=ID, all.x=TRUE)
in which case I only merge rows with exact string equality in the ID columns.
Is it possible to override the match criterion in the merge function somehow? Or is there another efficient way to achieve the same goal in R?