title: apply regexp and update column across data frames
body: <p>I have two data frames --- table A is the pattern table with reference names, and table B is the old name table. I want to subset table B, where it matches the pattern in table a, and when the cell matches, update the new column in B with the update column in A.</p>
  
  <p>I have referenced <a href="https://stackoverflow.com/questions/52372881/apply-regexp-in-one-data-frame-based-on-the-column-in-another-data-frame/52373072#52373072">apply regexp in one data frame based on the column in another data frame</a>, but it doesn't solve this case. </p>
  
  <pre><code>A &lt;- data.frame(pattern = c("ab", "be|eb", "cc", "dd"), 
                  ref = c("first", "second", "third", "forth"))
  B &lt;- data.frame(name = c("aa1", "bb1", "cab", "ccaa" "abed" ,"ddd", "ebba"))
  B$new = ""
  </code></pre>
  
  <p>And I want my result table to be :</p>
  
  <pre><code>name       new
  cab        first
  abed       second
  ccaa       third
  ddd        forth
  ebba       second
  </code></pre>
  
  <p>I was trying </p>
  
  <pre><code>for (i in 1:nrow(B)) {
    if (as.data.table(unlist(lapply(A$pattern, grepl, B$name))) == TRUE) {
      B$new[i] = A$update
    }
  }
  </code></pre>
  
  <p>Any one knows any better solution? I prefer using apply family, but I have no idea how can I add column with it. Any help is appreciated! </p>