Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

.Rhistory 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  1. load("C:/Users/alexi/Desktop/MS-DSPP/Spring 2022/PPOL628 Final Project/.RData")
  2. tweets <-
  3. #Read in tweets
  4. read_csv('data/tweets.csv')
  5. require(tidyverse)
  6. tweets <-
  7. #Read in tweets
  8. read_csv('data/tweets.csv')
  9. setwd("C:/Users/alexi/Desktop/MS-DSPP/Spring 2022/PPOL628 Final Project")
  10. tweets <-
  11. #Read in tweets
  12. read_csv('data/tweets.csv')
  13. length(unique(tweets$username))
  14. #Read in data
  15. tweets <-
  16. #Read in tweets
  17. read_csv('data/tweets.csv') %>%
  18. #Join elected officials
  19. left_join(
  20. read_csv('data/elected_officials.csv') %>%
  21. #Pivot so each individual account is a row
  22. pivot_longer(
  23. cols = c('officialTwitter',
  24. 'campaignTwitter',
  25. 'othertwitter'),
  26. names_to = 'account_type',
  27. values_to = 'twitter',
  28. values_drop_na = TRUE
  29. ) %>%
  30. #convert to lowercase so the join works
  31. mutate('twitter' = tolower(twitter)),
  32. by = c('username' = 'twitter')) %>%
  33. #Drop unused columns
  34. select(State:account_type,
  35. language,
  36. username,
  37. tweet) %>%
  38. #Filter just to english tweets
  39. filter(language == 'en') %>%
  40. #Concatenate tweets by individual name
  41. group_by(Name) %>%
  42. mutate('tweets' = paste0(tweet, collapse = "")) %>%
  43. #Drop unneeded columns again
  44. select(!c(tweet,account_type, username)) %>%
  45. #Select unique rows
  46. distinct()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...