Skip to content

Instantly share code, notes, and snippets.

@paldhous paldhous/edge_tweets.R
Last active Sep 30, 2019

Embed
What would you like to do?
# load required packages
library(rtweet)
library(tidyverse)
# get tweets (you will need a Twitter API token to run this code)
edge <- get_timeline("edge", n = 3200)
# function for frequency table
count_pct <- function(df) {
return(
df %>%
tally() %>%
mutate(n_pct = 100*n/sum(n))
)
}
# gender of tweets about Edge final question
questions <- edge %>%
filter(grepl("asks his final|asks her final|asks their final|ask their final", text, ignore.case = TRUE)) %>%
mutate(gender = case_when(grepl("asks his", text) == TRUE ~ "man",
grepl("asks her", text) == TRUE ~ "woman",
grepl("asks their", text) == TRUE ~ "neutral singular",
grepl("ask their", text) == TRUE ~ "neutral plural"))
questions_gender <- questions %>%
group_by(gender) %>%
count_pct()
# top mentioned accounts
mentions <- edge %>%
filter(!is.na(mentions_screen_name)) %>%
select(mentions_screen_name) %>%
unnest() %>%
filter(mentions_screen_name != "edge") %>%
group_by(mentions_screen_name) %>%
count_pct() %>%
arrange(-n)
# top retweeted accounts
retweets <- edge %>%
filter(!is.na(retweet_screen_name)) %>%
select(retweet_screen_name) %>%
filter(retweet_screen_name != "edge") %>%
group_by(retweet_screen_name) %>%
count_pct() %>%
arrange(-n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.