title: change the values in a column of a dataframe using another dataframe that contains key pairs
body: <p>I have the following sample df</p>
  <pre><code>df &lt;- data.frame(old=c(&quot;412oldname1&quot;,&quot;32oldname132&quot;,&quot;oldname141&quot;,&quot;132oldname2&quot;,&quot;oldname3&quot;,&quot;oldname4&quot;,&quot;oldname5&quot;))
  
          old
  1   412oldname1
  2   32oldname132
  3   oldname141
  4   132oldname2
  5   oldname3
  6   oldname4
  7   oldname5
  </code></pre>
  <p>I would like to extract rows using grepl and replace.</p>
  <pre><code>keypairs &lt;- data.frame(old=c(&quot;oldname1&quot;,&quot;oldname2&quot;),new=c(&quot;newname1&quot;,&quot;newname2&quot;))
  
         old      new
  1 oldname1 newname1
  2 oldname2 newname2
  </code></pre>
  <p>The desired dataframe would be:</p>
  <pre><code>        old
  1   newname1
  2   newname1
  3   newname1
  4   newname2
  </code></pre>
  <p>Ideally, I could replace the output of grepl with the patters, then use <code>left_join</code> and select the <code>new</code> column.</p>
  <p>So far, I have:</p>
  <pre><code>df %&gt;% filter(grepl(keypairs$old,collapse=&quot;|&quot;))
  # still trying to figure out what to do at this step
  %&gt;% left_join(keypairs) %&gt;% select(new)
  </code></pre>