title: Looping over two dataframes
body: <p>I have the following code lines and I want to do the text analysis for both male and female words using the fommands below</p>
  <pre><code>words_male &lt;- subset(Dec_10_Spreadsheet, Gender==&quot;Male&quot;)
  words_female&lt;- subset(Dec_10_Spreadsheet, Gender=&quot;Female&quot;)
  
  words_female&lt;- words_female %&gt;% 
    select(Text) %&gt;%
    unnest_tokens(word,Text) %&gt;%
    anti_join(stop_words) %&gt;%
    filter(word != &quot;meeting&quot;, word != &quot;speaking&quot;, word != &quot;government&quot;, word != &quot;house&quot;, word!= &quot;question&quot;, words!=&quot;issue&quot;, word!=&quot;policy&quot;,word!=&quot;speaker&quot;)
  
  
  
  words_female %&gt;% 
    count(word,sort=T) %&gt;% 
    slice(1:20) %&gt;% 
    ggplot(aes(x = reorder(word, n, function(n) -n), y = n)) + 
    geom_bar(stat = &quot;identity&quot;) + 
    theme(axis.text.x = element_text(angle = 60, hjust = 1)) + 
    xlab(&quot;&quot;)
  
  words_male&lt;- words_male %&gt;% 
    select(Text) %&gt;%
    unnest_tokens(word,Text) %&gt;%
    anti_join(stop_words) 
  
  
  words_male %&gt;% 
    count(word,sort=T) %&gt;% 
    slice(1:20) %&gt;% 
    ggplot(aes(x = reorder(word, n, function(n) -n), y = n)) + 
    geom_bar(stat = &quot;identity&quot;) + 
    theme(axis.text.x = element_text(angle = 60, hjust = 1)) + 
    xlab(&quot;&quot;)
  
  
  </code></pre>
  <p>I want to optimize this code so that it loops over the male and female datasets without having to repeat the lines twice. I might have to segment this data further as well into many different subsets so having a code like this will be very helpful. Any ideas? I will gift you a starbucks coffee :)</p>