title: How do I replace multiple strings in a R dataframe column
body: <p>I have a column in a data frame that is not well defined. For example, I have :</p>
  
  <pre><code> &gt; mydata$column1&lt;-c("abcAppledef","gsApple123hilhj","stBananaewfs","sfesBanana123sfeft",
  "stwefPearsfet","stwfePearabcseft","wefCarwefeEef","wefwaCarWFEe","wefaCarEFWefe")
  </code></pre>
  
  <p>I would like to re-define the column by replacing the strings with wildcard, and the outcome should be something like:</p>
  
  <pre><code>&gt; mydata$column1&lt;-c("Apple","Apple","Banana","Banana","Pear","Pear","Car","Car","Car")
  </code></pre>
  
  <p>I am using </p>
  
  <pre><code>&gt; mydata$column1&lt;-gsub('.*Apple.*','Apple',mydata$column1)
  
  &gt; mydata$column1&lt;-gsub('.*Banana.*','Banana',mydata$column1)
  
  &gt; mydata$column1&lt;-gsub('.*Pear.*','Pear',mydata$column1)
  
  &gt; mydata$column1&lt;-gsub('.*Car.*','Car',mydata$column1)
  </code></pre>
  
  <p>But I have many different kinds of patterns, and I would need to apply this on multiple tables as well. Is there a more efficient way to do this?
  Maybe a lookup table?</p>
  
  <p>Thanks.</p>