title: Partial match for a dataset using vector in R
body: <p>I have one dataset consisting of car brand names with other data (<em>test1</em>), and a vector of all the unique shortened car brand names (<em>test</em>).  </p>
  
  <pre><code>test&lt;-c("Rolls Royce", "Toyota", "Tesla", "BMW","Ford", "Mercedes")
  test1&lt;- data.frame(Brand = c("Mercedes Benz", "Bayerische Motoren Werke (BMW)",
                   "Ford Motor Corp.", "Rolls Royce", 
                   "Tesla", "Mercedes Benz", "Ford Motor"),
        Ratings = c(6,6,4,9,8,8,6))
  </code></pre>
  
  <p>How do I do a partial string match to the dataset (<em>test1</em>) using the string vector of unique car names (<em>test</em>) and change the Brand values of <em>test1</em> to search and match the values of <em>test</em>? </p>
  
  <p>I can do this for each entry, though I'd like to see if there's a faster way to obtain the result:</p>
  
  <pre><code>library(data.table)
  test1[test1$Brand %like% "Rolls Royce", ]$Brand &lt;-"Rolls Royce"
  test1[test1$Brand %like% "Toyota", ]$Brand &lt;-"Toyota"
  test1[test1$Brand %like% "Tesla", ]$Brand &lt;-"Tesla"
  test1[test1$Brand %like% "BMW", ]$Brand &lt;-"BMW"
  test1[test1$Brand %like% "Ford", ]$Brand &lt;-"Ford"
  test1[test1$Brand %like% "Mercedes", ]$Brand &lt;-"Mercedes"
  </code></pre>
  
  <p>This is the result I'd like to obtain for the above example:</p>
  
  <pre><code>data.frame(Brand = c("Mercedes", "BMW",
                   "Ford", "Rolls Royce", 
                   "Tesla", "Mercedes", "Ford"),
        Ratings = c(6,6,4,9,8,8,6))
  </code></pre>