title: test if words are in a string (grepl, fuzzyjoin?)
body: <p>I need to do a match and join on two data frames if the string from two columns of one data frame are contained in the string of a column from a second data frame.</p>
  <p>Example dataframe:</p>
  <pre class="lang-r prettyprint-override"><code>First &lt;- c(&quot;john&quot;, &quot;jane&quot;, &quot;jimmy&quot;, &quot;jerry&quot;, &quot;matt&quot;, &quot;tom&quot;, &quot;peter&quot;, &quot;leah&quot;)
  Last  &lt;- c(&quot;smith&quot;, &quot;doe&quot;, &quot;mcgee&quot;, &quot;bishop&quot;, &quot;gibbs&quot;, &quot;dinnozo&quot;, &quot;lane&quot;, &quot;palmer&quot;)
  Name  &lt;- c(&quot;mr john smith&quot;,&quot;&quot;, &quot;timothy t mcgee&quot;, &quot;dinnozo tom&quot;, &quot;jane  l doe&quot;, &quot;jimmy mcgee&quot;, &quot;leah elizabeth arthur palmer and co&quot;, &quot;jerry bishop the cat&quot;)
  ID    &lt;- c(&quot;ID1&quot;, &quot;ID2&quot;, &quot;ID3&quot;, &quot;ID4&quot;, &quot;ID5&quot;, &quot;ID6&quot;, &quot;ID7&quot;, &quot;ID8&quot;)
  
  df1 &lt;- data.frame(First, Last)
  df2 &lt;- data.frame(Name, ID)
  </code></pre>
  <p>So basically, I have <code>df1</code> which has fairly orderly names of people in first and last name; I have <code>df2</code>, which has names which may be organized as &quot;First Name, Last Name&quot;, or &quot;Last Name First Name&quot; or &quot;First Name MI Last Name&quot; or something else entirely that also contains the name. I need the <code>ID</code> column from <code>df2</code>. So I want to run a code to see if <code>df1$First</code> <strong>and</strong> <code>df2$Last</code> is somewhere in the string of <code>df2$Name</code>, and if it is have it pull and join <code>df2$ID</code> to <code>df1</code>.</p>
  <p>My R guru told me to use <code>fuzzy_left_join</code> from the <code>fuzzyjoin</code> package:</p>
  <pre class="lang-r prettyprint-override"><code>fzjoin &lt;- fuzzy_left_join(df1, df2, by = c(&quot;First&quot; = &quot;Name&quot;), match_fun = &quot;contains&quot;)
  </code></pre>
  <p>but it gives me an error where the argument is not logical; and I can't figure out how to rewrite it to do what I want; the <a href="https://rdrr.io/cran/fuzzyjoin/man/fuzzy_join.html" rel="nofollow noreferrer">documentation</a> says that <code>match_fun</code> should be <code>TRUE</code> or <code>FALSE</code>, but I don't know what to do with that. Also, it only matches on <code>df1$First</code> rather than <code>df1$First</code> and <code>df1$Last</code>. I think I might be able to use the <a href="https://stackoverflow.com/questions/10128617/test-if-characters-are-in-a-string">grepl</a>, but not sure how based on examples I've seen. Any advice?</p>