Skip to content

Instantly share code, notes, and snippets.

@brandmaier
Created June 2, 2020 06:31
Show Gist options
  • Save brandmaier/729896d7f534d3e1075508934260faa2 to your computer and use it in GitHub Desktop.
Save brandmaier/729896d7f534d3e1075508934260faa2 to your computer and use it in GitHub Desktop.
Create histogram from Pokémon puzzle challenge
library(rtweet)
library(stringr)
# get last 100 tweets
tweets <- search_tweets("jonasobleser",n = 100)
# extract numbers with one or more digits
numbers <- sapply(tweets$text,
function(x) {
as.numeric(str_extract(x, "([0-9]+)"))
})
# plot histogram
hist(numbers, main = paste0("Mean = ",
round(mean(numbers, na.rm = TRUE))))
@brandmaier
Copy link
Author

Screenshot 2020-06-02 at 08 31 49

@brandmaier
Copy link
Author

Warning. This just takes the last 100 tweets. Is there a better way to extract all replies from a given tweet?

@avakiai
Copy link

avakiai commented Jun 2, 2020

Fantastic. It seems like 18,000 is the limit for the function, but setting retryonratelimit to TRUE might let you fetch more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment