title: Remove certain words in string from column in dataframe in R
body: <p>I have a dataset in R that lists out a bunch of company names and want to remove words like "Inc", "Company", "LLC", etc. for part of a clean-up effort. I have the following sample data:</p>
  
  <p>sampleData</p>
  
  <pre><code>  Location             Company
  1 New York, NY         XYZ Company
  2 Chicago, IL          Consulting Firm LLC
  3 Miami, FL            Smith &amp; Co.
  </code></pre>
  
  <p>Words I do not want to include in my output:</p>
  
  <pre><code>stopwords = c("Inc","inc","co","Co","Inc.","Co.","LLC","Corporation","Corp","&amp;")
  </code></pre>
  
  <p>I built the following function to break out each word, remove the stopwords, and then bring the words back together, but it is not iterating through each row of the dataset.</p>
  
  <pre><code>removeWords &lt;- function(str, stopwords) {
    x &lt;- unlist(strsplit(str, " "))
    paste(x[!x %in% stopwords], collapse = " ")
  }
  
  removeWords(sampleData$Company,stopwords)
  </code></pre>
  
  <p>The output for the above function looks like this:</p>
  
  <pre><code>[1] "XYZ Company Consulting Firm Smith"
  </code></pre>
  
  <p>T
  he output should be:</p>
  
  <pre><code> Location              Company
  1 New York, NY         XYZ Company
  2 Chicago, IL          Consulting Firm
  3 Miami, FL            Smith
  </code></pre>
  
  <p>Any help would be appreciated.</p>