title: How to use apply in R with two data frames?
body: <p><strong>Background</strong></p>
  
  <p>I have a dataframe with ~1M rows of text. I want to replace a large list of custom stopwords, which the TM package cannot handle. The list consists of ~37K words. I have the following code that works and it takes a while, but I want to improve the code with an apply function.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>I don't know how to use content from two dataframes in the applicable apply function. Here is my code:</p>
  
  <pre><code>stopwords &lt;- read.table("stopwords.csv", header=TRUE, quote="\"", stringsAsFactors=FALSE)
  corpus &lt;- read.delim("corpus.txt", header=TRUE, stringsAsFactors=FALSE)
  
  for(i in 1:nrow(stopwords)){
    corpus$text &lt;- gsub(paste("\\&lt;",stopwords$list[i],"\\&gt;", sep=""), "", corpus$text)
    message(paste(i, stopwords$list[i], sep=" - ")) #Show in console
  }
  </code></pre>
  
  <p>I also display the current count/word in the console to track progress, but once I have an apply function working, I will wrap it in the pbapply package to get a proper progress bar.</p>
  
  <p><strong>Sample Data</strong></p>
  
  <p><em>Corpus Dataframe</em> - Single column with "text" as header<br>
  police worlds acted decisively premier mike baird<br>
  police operation map affected traffic area live traffic nsw<br>
  commissioner scipione number hostages undisclosed<br>
  nsw premier manner avoid martin place aware vigilant<br>
  happening thoughts heart hostages families affected<br>
  lindt cafe nice brave mighty warrior allah ikea dickhead<br>
  police advising citizens business avoid marketplaces<br></p>
  
  <p><em>Stopwords</em> Data Frame - Single column with "list" as header.<br>
  aaa<br>
  aaaa<br>
  aaaaaaand<br>
  aaaaand<br>
  aaaargh<br>
  aaack<br>
  aaahh<br>
  aaahhhh<br>
  aaalll<br>
  aaand<br>
  aaarse<br>
  aachen<br>
  aadityanath<br></p>