This is a followup question to: R- merge two data frames but some values have semi colon in them which has been addressed by contributor: agstudy.
The actual data discussed in the link is a bit more complex and i have been stuck for a while.
This is what my dataframe (df2) looks like:
myIDColumn someName somevalue
AB gsdfg 123
CD tfgsdfg 234
EF sfdgsf 365
GH gdfgb 53453
IJ sr 64564
KL sfsdv 4234234
MN ewrwe 5
OP dsfsss 3453
QR gggg 667
ST dss 7567
UV hhhhjf 55
WX dfadasad 8657
YZ ghfgh 1234
ABC gdgfg 234455
VCB hgjkk 5555667
This is what my df1 looks like:
ID someText someThing
AB ada 12
CD;EF;QR dfsdf 13
IJ fgfgd 14
KL fgdg 15
MN gh 16
OP;WX jhjhj 17
WW ghjgjhgjghj 18
YZ kkl 19
This is what i was hoping to get as an output:
I can merge the two well by using:
mm <- merge(df2,df1,by.y='ID',by.x='myIDColumn',all.y=TRUE)
but after that no idea how to proceed further.
Any help is really appreciated. Thanks.
df1:
structure(list(ID = structure(1:8, .Label = c("AB", "CD;EF;QR",
"IJ", "KL", "MN", "OP;WX", "WW", "YZ"), class = "factor"), someText = structure(c(1L,
2L, 4L, 3L, 5L, 7L, 6L, 8L), .Label = c("ada", "dfsdf", "fgdg",
"fgfgd", "gh", "ghjgjhgjghj", "jhjhj", "kkl"), class = "factor"),
someThing = 12:19), .Names = c("ID", "someText", "someThing"
), class = "data.frame", row.names = c(NA, -8L))
df2:
structure(list(myIDColumn = structure(c(1L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 14L, 15L, 2L, 13L), .Label = c("AB", "ABC",
"CD", "EF", "GH", "IJ", "KL", "MN", "OP", "QR", "ST", "UV", "VCB",
"WX", "YZ"), class = "factor"), someName = structure(c(9L, 15L,
12L, 5L, 14L, 13L, 4L, 2L, 7L, 3L, 11L, 1L, 8L, 6L, 10L), .Label = c("dfadasad",
"dsfsss", "dss", "ewrwe", "gdfgb", "gdgfg", "gggg", "ghfgh",
"gsdfg", "hgjkk", "hhhhjf", "sfdgsf", "sfsdv", "sr", "tfgsdfg"
), class = "factor"), somevalue = c(123L, 234L, 365L, 53453L,
64564L, 4234234L, 5L, 3453L, 667L, 7567L, 55L, 8657L, 1234L,
234455L, 5555667L)), .Names = c("myIDColumn", "someName", "somevalue"
), class = "data.frame", row.names = c(NA, -15L))