Advertisement
Guest User

Untitled

a guest
Jan 13th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement