title: Inserting a new column with values, from another dataframe, based on another column value in R
body: <p>I have 2 dataframes.</p>
  <p>For <strong>df1</strong>, they are transaction records:</p>
  <pre><code>date | description   | amount
  =============================
  xxxx | insurance-abc | 100
  xxxx | grocery-xyz   | 50
  xxxx | insurance-jkl | 150
  xxxx | misc-spend    | 50
  xxxx | grocery-abc   | 70
  </code></pre>
  <p>For <strong>df2</strong>, it contains category information</p>
  <pre><code>description | category
  ======================
  insurance   | INS
  grocery     | GRY
  </code></pre>
  <p>The end state, I am looking to have this inside <strong>df3</strong></p>
  <pre><code>date | description   | amount | category
  ========================================
  xxxx | insurance-abc | 100    | INS
  xxxx | grocery-xyz   | 50     | GRY
  xxxx | insurance-jkl | 150    | INS
  xxxx | misc-spend    | 50     |
  xxxx | grocery-abc   | 70     | GRY
  </code></pre>
  <p>I attempted to use mutate() and ifelse() and grepl() for partial string match, but I think this is  not the way to go. Because as I find certain keywords, I will add them into df2 and have newer categories.</p>
  <p>Is there to do a partial string search on existing column and where there is a match, create the new category and insert value from another datatable, like the example I cited above?</p>
  <p>Thanks!</p>
  <p>df1 and df2 for copy/paste:</p>
  <pre><code>df1 &lt;- tibble::tribble(
    ~date, ~description, ~amount,
    &quot;xxxx&quot;, &quot;insurance-abc&quot;,100,
    &quot;xxxx&quot;, &quot;grocery-xyz&quot;,  50,
    &quot;xxxx&quot;, &quot;insurance-jkl&quot;,150,
    &quot;xxxx&quot;, &quot;misc-spend&quot;, 50,
    &quot;xxxx&quot;, &quot;grocery-abc&quot;,  70
    )
  
  df2 &lt;- tibble::tribble(
    ~description, ~category,
    &quot;insurance&quot;, &quot;INS&quot;,
    &quot;grocery&quot;,   &quot;GRY&quot;
  )
  </code></pre>