daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Jan 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(dplyr)
  2. library(purrr)
  3. library(twitteR)
  4. library(tidytext)
  5. library(stringr)
  6.  
  7. setup_twitter_oauth("x",
  8.                     "x",
  9.                     "x-x",
  10.                     "x")
  11.  
  12. elon <- userTimeline("elonmusk", n = 3200)
  13. elon_df<- tbl_df(map_df(elon, as.data.frame))
  14.  
  15. reg <- "([^A-Za-z\\d#@']|'(?![A-Za-z\\d#@]))"
  16.  
  17. tweet_words <- elon_df %>%
  18.   filter(!str_detect(text, '^"')) %>%
  19.   mutate(text = str_replace_all(text, "https://t.co/[A-Za-z\\d]+|&amp;", "")) %>%
  20.   unnest_tokens(word, text, token = "regex", pattern = reg) %>%
  21.   filter(!word %in% stop_words$word,
  22.          str_detect(word, "[a-z]"))
  23.  
  24. tweet_words %>%
  25.   group_by(word) %>%
  26.   summarise(no_rows = length(word)) %>%
  27.   arrange(desc(no_rows))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top