title: R - Replace multiple patterns with multiple ids
body: <p>This was partially already tackled in others posts but unfortunately I could not make it run properly on my side.</p>
  <p>I have a data frame full of texts, and there are certain words that I want replaced by a unique name.</p>
  <p>So, if we see the table bellow, I would want to replace each of the words &quot;Banana Apple Tomato&quot; by the word &quot;Fruit&quot; (the word Fruit can show up multiple times, that is ok)
  I also want to replace &quot;Cod Pork Beef&quot; by the word &quot;Animals&quot;</p>
  <p>I have a full excel file where this mapping was done.
  The excel file has two columns.
  On column A, we have the unique name (like Fruit and Animals). On column B, we have the words that we want to replace on the text (Like Banana, Apple, Tomato).</p>
  <p>The code I came up was:</p>
  <pre><code>hous &lt;- read.table(header = TRUE, 
                     stringsAsFactors = FALSE, 
                     text=&quot;HouseType HouseTypeNo
  'Banana Apple Tomato Honey' 'Onion Garlic Pepper Sugar'
  'Cod Pork Beef' 'Mushrooms Soya Eggs' &quot;)
  
  maps &lt;- read.table(header = TRUE, 
                             stringsAsFactors = FALSE, 
                             text=&quot;UniqueID Names
  'Fruit' 'Banana'
  'Fruit' 'Apple'
  'Fruit' 'Tomato'
  'Animals' 'Cod'
  'Animals' 'Pork'
  'Animals' 'Beef'&quot;)
  
  hous %&gt;% str_replace_all( pattern = maps$Names, replacement = maps$UniqueID)
  *#Warning message:
  In stri_replace_all_regex(string, pattern, fix_replacement(replacement),  :
    argument is not an atomic vector; coercing*
  
  </code></pre>
  <p>I cannot make it work.
  I basically just wanna look up for certain words, and replace them with some unique ids.
  It doesn't sound complicated, but I cannot make it run.</p>
  <p>Just a few points: in my real data set I have thousands of words and IDs. I have seen in other examples people writing their ids, patters and replacements by hand. In my case that is not applicable.</p>
  <p>The final output would be something like this:</p>
  <pre><code>hous &lt;- read.table(header = TRUE, 
                     stringsAsFactors = FALSE, 
                     text=&quot;HouseType HouseTypeNo
  'Fruit Fruit Fruit Honey' 'Onion Garlic Pepper Sugar'
  'Animal Animal Animal' 'Mushrooms Soya Eggs' &quot;)
  </code></pre>
  <p>Any help is appreciated.</p>
  <p>Best regards</p>