<div> You may have heard that two researchers at Clemson University <a href="https://bigthink.com/stephen-johnson/analysis-of-3-million-russian-troll-tweets-reveals-5-distinct-types-of-accounts">analyzed almost 3 millions tweets from the Internet Research Agency (IRA)</a> – a “Russian troll factory”. In partnership with <a href="https://fivethirtyeight.com/features/why-were-sharing-3-million-russian-troll-tweets/">FiveThirtyEight</a>, they made all of their data available on <a href="https://github.com/fivethirtyeight/russian-troll-tweets/">GitHub</a>. So of course, I had to read the files into R, which I was able to do with this code:
<div>
<div>
<div>
<pre><span>files</span> <span>&lt;-</span> <span>c</span><span>(</span><span>&quot;IRAhandle_tweets_1.csv&quot;</span><span>,</span><br>           <span>&quot;IRAhandle_tweets_2.csv&quot;</span><span>,</span><br>           <span>&quot;IRAhandle_tweets_3.csv&quot;</span><span>,</span><br>           <span>&quot;IRAhandle_tweets_4.csv&quot;</span><span>,</span><br>           <span>&quot;IRAhandle_tweets_5.csv&quot;</span><span>,</span><br>           <span>&quot;IRAhandle_tweets_6.csv&quot;</span><span>,</span><br>           <span>&quot;IRAhandle_tweets_7.csv&quot;</span><span>,</span><br>           <span>&quot;IRAhandle_tweets_8.csv&quot;</span><span>,</span><br>           <span>&quot;IRAhandle_tweets_9.csv&quot;</span><span>)</span><br><span>my_files</span> <span>&lt;-</span> <span>paste0</span><span>(</span><span>&quot;~/Downloads/russian-troll-tweets-master/&quot;</span><span>,files)</span><br><br><span>each_file</span> <span>&lt;-</span> <span>function</span><span>(</span><span>file</span><span>) {</span><br>  <span>tweet</span> <span>&lt;-</span> <span>read_csv</span><span>(file) }</span><br><br><span>library</span><span>(tidyverse)</span><br></pre>
</div>
<div>
<pre><span>tweet_data</span> <span>&lt;-</span> <span>NULL</span><br><span>for</span> <span>(file</span> <span>in</span> <span>my_files) {</span><br>  <span>temp</span> <span>&lt;-</span> <span>each_file</span><span>(file)</span><br>  <span>temp</span><span>$</span><span>id</span> <span>&lt;-</span> <span>sub</span><span>(</span><span>&quot;.csv&quot;</span><span>,</span> <span>&quot;&quot;</span><span>, file)</span><br>  <span>tweet_data</span> <span>&lt;-</span> <span>rbind</span><span>(tweet_data, temp)</span><br><span>}</span><br></pre>
</div>
<p>Note that this is a large file, with 2,973,371 observations of 16 variables. Let’s do some cleaning of this dataset first. The researchers, Darren Linvill and Patrick Warren, identified 5 majors types of trolls: </p>
<blockquote>
<ul>
<li>Right Troll: These Trump-supporting trolls voiced right-leaning, populist messages, but “rarely broadcast traditionally important Republican themes, such as taxes, abortion, and regulation, but often sent divisive messages about mainstream and moderate Republicans…They routinely denigrated the Democratic Party, e.g. @LeroyLovesUSA, January 20, 2017, “#ThanksObama We’re FINALLY evicting Obama. Now Donald Trump will bring back jobs for the lazy ass Obamacare recipients,” the authors wrote.</li>
<li>Left Troll: These trolls mainly supported Bernie Sanders, derided mainstream Democrats, and focused heavily on racial identity, in addition to sexual and religious identity. The tweets were “clearly trying to divide the Democratic Party and lower voter turnout,” the authors told FiveThirtyEight.</li>
<li>News Feed: A bit more mysterious, news feed trolls mostly posed as local news aggregators who linked to legitimate news sources. Some, however, “tweeted about global issues, often with a pro-Russia perspective.”</li>
<li>Hashtag Gamer: Gamer trolls used hashtag games—a popular call/response form of tweeting—to drum up interaction from other users. Some tweets were benign, but many “were overtly political, e.g. @LoraGreeen, July 11, 2015, “#WasteAMillionIn3Words Donate to #Hillary.”</li>
<li>Fearmonger: These trolls, who were least prevalent in the dataset, spread completely fake news stories, for instance “that salmonella-contaminated turkeys were produced by Koch Foods, a U.S. poultry producer, near the 2015 Thanksgiving holiday.”</li>
</ul>
</blockquote>
<p>But a quick table of the results of the variable, account_category, shows 8 in the dataset.</p>
<div>
<div>
<div>
<pre><span>table</span><span>(tweet_data</span><span>$</span><span>account_category)</span><br></pre>
</div>
<div>
<pre>## <br>##   Commercial   Fearmonger HashtagGamer    LeftTroll     NewsFeed <br>##       122582        11140       241827       427811       599294 <br>##   NonEnglish   RightTroll      Unknown <br>##       837725       719087        13905<br></pre>
</div>
</div>
</div>
<p>The additional three are Commercial, Non-English, and Unknown. At the very least, we should drop the Non-English tweets, since those use Russian characters and any analysis I do will assume data are in English. I’m also going to keep only a few key variables. Then I’m going to clean up this dataset to remove links, because I don’t need those for my analysis – I certainly wouldn’t want to follow them to their destination. If I want to free up some memory, I can then remove the large dataset.</p>
<div>
<div>
<div>
<pre><span>reduced</span> <span>&lt;-</span> <span>tweet_data</span> <span>%>%</span><br>  <span>select</span><span>(author,content,publish_date,account_category)</span> <span>%>%</span><br>  <span>filter</span><span>(account_category</span> <span>!=</span> <span>&quot;NonEnglish&quot;</span><span>)</span><br><br><span>library</span><span>(qdapRegex)</span><br></pre>
</div>
<div>
<pre>## <br>## Attaching package: 'qdapRegex'<br></pre>
</div>
<div>
<pre><span>reduced</span><span>$</span><span>content</span> <span>&lt;-</span> <span>rm_url</span><span>(reduced</span><span>$</span><span>content)</span><br><br><span>rm</span><span>(tweet_data)</span><br></pre>
</div>
</div>
</div>
<p>Now we have a dataset of 2,135,646 observations of 4 variables. I’m planning on doing some analysis on my own of this dataset – and will of course share what I find – but for now, I thought I’d repeat a technique I’ve covered on this blog and demonstrate a new one. </p>
<div>
<div>
<div>
<pre><span>library</span><span>(tidytext)</span><br><br><span>tweetwords</span> <span>&lt;-</span> <span>reduced</span> <span>%>%</span><br>  <span>unnest_tokens</span><span>(word, content)</span> <span>%>%</span><br>  <span>anti_join</span><span>(stop_words)</span><br></pre>
</div>
<div>
<pre>## Joining, by = &quot;word&quot;<br></pre>
</div>
<div>
<pre><span>wordcounts</span> <span>&lt;-</span> <span>tweetwords</span> <span>%>%</span><br>  <span>count</span><span>(account_category, word,</span> <span>sort</span> <span>=</span> <span>TRUE</span><span>)</span> <span>%>%</span><br>  <span>ungroup</span><span>()</span><br><br><span>head</span><span>(wordcounts)</span><br></pre>
</div>
<div>
<pre>## # A tibble: 6 x 3<br>##   account_category word          n<br>##   </pre></div></div></div></div></div></div>