Last active
January 2, 2020 02:09
-
-
Save rafapereirabr/45d7af12e0aaca20e4afd17f8a46f6bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### how to use R to find your most popular tweet of 2019 | |
# code by @nnstats | |
library(rtweet) | |
library(tidyverse) | |
library(lubridate) | |
show_most_popular_tweet <- function(user, year){ | |
y <- year | |
get_timeline(user, n=3200) %>% | |
mutate(year = year(created_at)) %>% | |
filter(year == y) %>% | |
arrange(-favorite_count) %>% | |
slice(1) %>% | |
pull(status_id) %>% | |
paste0('https://twitter.com/', user, '/status/', .) %>% | |
browseURL() | |
} | |
show_most_popular_tweet(user = 'UrbanDemog', year = 2018) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2018: https://twitter.com/UrbanDemog/status/977880572214300672
2019: https://twitter.com/UrbanDemog/status/1193132906979430400