title: Efficient method to return first match between two arrays
body: <p>I'm looking to to categorize bank transactions using R (I'm most familiar with the dplyr package). I have two data frames: </p>
  
  <ul>
  <li><code>trans_data</code>: holds the transaction data (importantly a transaction # and description)</li>
  <li><code>trans_categories</code>: holds match criteria and category names</li>
  </ul>
  
  <p>I'm looking to add a column to <code>trans_data</code> that includes the first item in <code>trans_categories</code> that fits the criteria.</p>
  
  <p>For example, given the following data frames:</p>
  
  <pre><code>trans_data = data.frame(
     "number" = c("abc123", "def456", "ghi789"), 
     "description" = c("transfer to x000", "transfer to x000", "transfer to x111"), 
     "number_description" = paste0(number, "-", description)   #sloppy here, but intended to concatenate prior two columns
  )
  
  trans_categories = data.frame(
     "criteria" = c("abc123", "transfer to x000", "transfer"), 
     "category" = c("expense reimbursement", "transfer to x000", "transfer")
  )
  
  </code></pre>
  
  <p>I'd like to append a column to <code>trans_data</code> that returns <code>c("expense reimbursement", "transfer to x000", "transfer")</code>. In other words, based on the <code>number_description</code> column in <code>trans_data</code>, we find the first instance where <code>trans_categories$criteria</code> matches, and return the corresponding value in <code>trans_categories$category</code>. </p>
  
  <p>I can do this with some sort of a loop that breaks when a match is found, but I assume that this is inelegant / slow for large data frames.</p>