title: How to replace multiple values among multiple columns in R dataframe?
body: <p>Say I have the following dataframe (the real one is 10 labelx columns):</p>
  
  <pre><code>id &lt;- c(1,2,3,4,5,6,7,8)
  label1 &lt;- c("apple","shoe","banana","hat","dog","radio","tree","pie")
  label2 &lt;- c("apple","sneaker","fruit","beanie","pet","ipod","doug fir","pie")
  df &lt;- data.frame(id,label1,label2)
  </code></pre>
  
  <p>And I would like to replace all items in the label columns with a word that categorizes it.</p>
  
  <pre><code>food &lt;- c("apple","banana","pie","fruit")
  clothing &lt;- c("shoe","hat","beanie")
  entertainment &lt;- c("radio","ipod","mp3 player","phone")
  forest &lt;- c("tree","doug fir","redwood","forest")
  </code></pre>
  
  <p>I've tried something like the following:</p>
  
  <pre><code>column_list &lt;- c("label1","label2")
  new_df &lt;- df
  
  for(i in 1:2) {
    new_df &lt;- new_df %&gt;%
    mutate(parse(text=column_list[i-1]) = replace(parse(text=column_list[i-1]),
                        (parse(text=column_list[i-1]) %in% food),
                        "food"))
  }
  </code></pre>
  
  <p>I don't have to do it this way, easier is fine too. Tidyverse preferred. How do I replace multiple values among multiple columns in R dataframe? </p>