Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(dplyr)
- library(purrr)
- library(twitteR)
- library(tidytext)
- library(stringr)
- setup_twitter_oauth("x",
- "x",
- "x-x",
- "x")
- elon <- userTimeline("elonmusk", n = 3200)
- elon_df<- tbl_df(map_df(elon, as.data.frame))
- reg <- "([^A-Za-z\\d#@']|'(?![A-Za-z\\d#@]))"
- tweet_words <- elon_df %>%
- filter(!str_detect(text, '^"')) %>%
- mutate(text = str_replace_all(text, "https://t.co/[A-Za-z\\d]+|&", "")) %>%
- unnest_tokens(word, text, token = "regex", pattern = reg) %>%
- filter(!word %in% stop_words$word,
- str_detect(word, "[a-z]"))
- tweet_words %>%
- group_by(word) %>%
- summarise(no_rows = length(word)) %>%
- arrange(desc(no_rows))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement