title: New column using grep to find strings in existing column in R
body: <p>My <code>dataset</code> has a column <code>GeogPreferences</code> which contains multiple strings in a single row. I have a vector of strings <code>region</code> that I want to use to search in this column. I am creating a new column <code>geog</code> and if the <code>GeogPreferences</code> contains any of the strings in <code>geog</code>, I want to retain the same text from the <code>GeogPreferences</code>, else I just replace the text by "All"</p>
  
  <p>My sample code is:</p>
  
  <pre><code>myDf &lt;- structure(list(GeogPreferences = structure(1:4, .Label = c("Asia, Central and East Europe, Europe, North America, West Europe, Australia, Belgium, Czech Republic, France, Germany, India, Italy, Luxembourg, Netherlands, Poland, Romania, Spain, UK, US", 
  "Europe, North America, West Europe, US", "Global, North America", 
  "Northeast, Southeast, West, US"), class = "factor")), .Names = "GeogPreferences", class = "data.frame", row.names = c(NA, 
  -4L))
  
  region &lt;- c("Northeast","Southeast","West","Midwest","Southwest")
  
  myDf$geog &lt;- ifelse((grepl(paste(region, collapse = "|"), myDf$GeogPreferences)),myDf$GeogPreferences, c("All"))
  </code></pre>
  
  <p>The problem is <code>grep</code> considers strings like "West Europe" to be in the list <code>region</code> because of the word "West" and I get the following output</p>
  
  <pre><code>geog
  1
  2
  All
  4
  </code></pre>
  
  <p>I am expecting an output like:</p>
  
  <pre><code>geog
  All
  All
  All
  Northeast, Southeast, West, US  
  </code></pre>
  
  <p>Is there a way to use grep or any other function to get this output?</p>