Code, in development, for paper:
#Packages and libraries
if(!require(tidyverse)) install.packages("tidyverse")
library(tidyverse)
#Loading all data collected so far and showing column names
AllData <- read.csv("Members of Congress 540.csv", skip = 6)
colnames(AllData)
## [1] "Query.Id"
## [2] "Query.Name"
## [3] "Date"
## [4] "Title"
## [5] "Snippet"
## [6] "Url"
## [7] "Domain"
## [8] "Sentiment"
## [9] "Page.Type"
## [10] "Language"
## [11] "Country.Code"
## [12] "Continent.Code"
## [13] "Continent"
## [14] "Country"
## [15] "City.Code"
## [16] "Account.Type"
## [17] "Added"
## [18] "Assignment"
## [19] "Author"
## [20] "Avatar"
## [21] "Category.Details"
## [22] "Checked"
## [23] "City"
## [24] "Display.URLs"
## [25] "Entity.Info"
## [26] "Expanded.URLs"
## [27] "Facebook.Author.ID"
## [28] "Facebook.Comments"
## [29] "Facebook.Likes"
## [30] "Facebook.Role"
## [31] "Facebook.Shares"
## [32] "Facebook.Subtype"
## [33] "Full.Name"
## [34] "Full.Text"
## [35] "Gender"
## [36] "Hashtags"
## [37] "Impact"
## [38] "Impressions"
## [39] "Instagram.Comments"
## [40] "Instagram.Followers"
## [41] "Instagram.Following"
## [42] "Instagram.Interactions.Count"
## [43] "Instagram.Likes"
## [44] "Instagram.Posts"
## [45] "Interest"
## [46] "Last.Assignment.Date"
## [47] "Latitude"
## [48] "Location.Name"
## [49] "Longitude"
## [50] "Media.Filter"
## [51] "Media.URLs"
## [52] "Mentioned.Authors"
## [53] "Original.Url"
## [54] "Priority"
## [55] "Professions"
## [56] "Resource.Id"
## [57] "Short.URLs"
## [58] "Starred"
## [59] "Status"
## [60] "Subtype"
## [61] "Tags"
## [62] "Thread.Author"
## [63] "Thread.Created.Date"
## [64] "Thread.Entry.Type"
## [65] "Thread.Id"
## [66] "Thread.URL"
## [67] "Total.Monthly.Visitors"
## [68] "Twitter.Author.ID"
## [69] "Twitter.Channel.Role"
## [70] "Twitter.Followers"
## [71] "Twitter.Following"
## [72] "Twitter.Reply.Count"
## [73] "Twitter.Reply.to"
## [74] "Twitter.Retweet.of"
## [75] "Twitter.Retweets"
## [76] "Twitter.Likes"
## [77] "Twitter.Tweets"
## [78] "Twitter.Verified"
## [79] "Updated"
## [80] "Reach..new."
## [81] "Air.Type"
## [82] "Author.Verified.Type"
## [83] "Blog.Name"
## [84] "Broadcast.Media.Url"
## [85] "Broadcast.Type"
## [86] "Content.Source"
## [87] "Content.Source.Name"
## [88] "Copyright"
## [89] "Engagement.Type"
## [90] "Is.Syndicated"
## [91] "Item.Review"
## [92] "Linkedin.Comments"
## [93] "Linkedin.Engagement"
## [94] "Linkedin.Impressions"
## [95] "Linkedin.Likes"
## [96] "Linkedin.Shares"
## [97] "Linkedin.Sponsored"
## [98] "Linkedin.Video.Views"
## [99] "Media.Type"
## [100] "Page.Type.Name"
## [101] "Parent.Blog.Name"
## [102] "Parent.Post.Id"
## [103] "Pub.Type"
## [104] "Publisher.Sub.Type"
## [105] "Rating"
## [106] "Reddit.Author.Awardee.Karma"
## [107] "Reddit.Author.Awarder.Karma"
## [108] "Reddit.Author.Karma"
## [109] "Reddit.Comments"
## [110] "Reddit.Score"
## [111] "Reddit.Score.Upvote.Ratio"
## [112] "Region"
## [113] "Region.Code"
## [114] "Root.Blog.Name"
## [115] "Root.Post.Id"
## [116] "Sina.Weibo.Author.Id"
## [117] "Sina.Weibo.Bi.Followers"
## [118] "Sina.Weibo.Favourites.Count"
## [119] "Sina.Weibo.Followers"
## [120] "Sina.Weibo.Following"
## [121] "Sina.Weibo.Post.Count"
## [122] "Sina.Weibo.Raw.Location"
## [123] "Subreddit"
## [124] "Subreddit.Subscribers"
## [125] "Subscriptions"
## [126] "Weblog.Title"
## [127] "X.Wizard.5..Content.Types...Images"
## [128] "X.Wizard.5..Content.Types...Videos"
## [129] "X.Wizard.5..Hashtags....mtsutruebluecore"
## [130] "X.Wizard.5..Hashtags....trueblue"
## [131] "X.Wizard.5..Hashtags....truebluecore"
## [132] "X.Wizard.5..Mention.Types...Audience.Posts...RTs...Audience.Posts"
## [133] "X.Wizard.5..Mention.Types...Audience.Posts...RTs...Audience.RTs"
## [134] "X.Wizard.5..Mention.Types...Owned.Posts...RTs"
## [135] "Emotion"
#Loading new data and adding it to data collected so far
AddData <- read.csv("Members of Congress 540 January.csv", skip = 6)
AllData <- rbind(AllData,AddData)
#Selecting columns needed for the analysis
KeptData <- select(AllData,
Date,
Url,
Author,
Full.Text,
Twitter.Reply.Count,
Twitter.Retweets,
Twitter.Likes,
Reach..new.)
colnames(KeptData)
## [1] "Date" "Url" "Author"
## [4] "Full.Text" "Twitter.Reply.Count" "Twitter.Retweets"
## [7] "Twitter.Likes" "Reach..new."
#Formatting "Date" as POSIXct object
KeptData$Date <- as.POSIXct(KeptData$Date, tz = "America/Chicago")
#Sorting by Date
KeptData <- arrange(KeptData,Date)
#Re-expressing "Date" as "WeekOf," the Monday of the week containing "Date."
KeptData <- KeptData %>%
mutate(WeekOf = floor_date(Date,
unit = "week"))
#Grouping by week, averaging likes, retweets, and replies, and counting tweets.
WeeklyData <- KeptData %>%
group_by(WeekOf) %>%
summarize(Avg_Likes = mean(Twitter.Likes),
Avg_Retweets = mean(Twitter.Retweets),
Avg_Replies = mean(Twitter.Reply.Count),
Tweet_Count = n())
head(WeeklyData, 20)
## # A tibble: 3 × 5
## WeekOf Avg_Likes Avg_Retweets Avg_Replies Tweet_Count
## <dttm> <dbl> <dbl> <dbl> <int>
## 1 2024-01-14 00:00:00 367. 102. 79.6 3701
## 2 2024-01-21 00:00:00 332. 73.7 114. 64
## 3 2024-02-04 00:00:00 456. 118. 122. 4605