I have two data frames
df1
+-------+---------+
| Id | Title |
+-------+---------+
| 1 | AAA |
| 2 | BBB |
| 3 | CCC |
+-------+---------+
AND
df2
+-------+---------------+------------------------------------+
| Id | Sub | Body |
+-------+---------------+------------------------------------+
| 1 | some sub1 | some mail body AAA some text here |
| 2 | some sub2 | some text here BBB continues here |
| 3 | some sub3 | some text AAA present here |
| 4 | some sub4 | AAA string is present here also |
| 5 | some sub5 | CCC string is present here |
+-------+---------------+------------------------------------+
I want to match the Title from df1 with the Body column of the df2,
if title string is present in Body column, then both the rows should be joined, the output data frame should be like:
df3
+----------+---------------+------------------------------------+
| Title | Sub | Body |
+----------+---------------+------------------------------------+
| AAA | some sub1 | some mail body AAA some text here |
| BBB | some sub2 | some text here BBB continues here |
| AAA | some sub3 | some text AAA present here |
| AAA | some sub4 | AAA string is present here also |
| CCC | some sub5 | CCC string is present here |
+----------+---------------+------------------------------------+
Error in grepl(df1$title[idx], df2$body) : invalid 'pattern' argument. I m sorry, i missed one more thing in my question, in the Title i have string like "AAA BB" not just "AAA". I tried your code with the data "AAA BB" it is giving the following errorError in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 1, 0. - Bharath KM