Bachelor thesis: "The influence of sensational issues on the political agenda setting in social media"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

politiker-transform.R 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. require(XML)
  2. require(stringr)
  3. setwd("~/Dokumente/Uni/Aktuell/BA-Arbeit/uni-ba-issuecomp")
  4. mdb <- readLines("politiker2.txt")
  5. mdb_names <- unlist(str_extract_all(mdb, ".+?,.+?,"))
  6. mdb_names <- str_replace_all(mdb_names, ",$", "")
  7. mdb_party <- unlist(str_extract_all(mdb, "[[:alnum:] /]+$"))
  8. mdb_party <- str_replace_all(mdb_party, "^ ", "")
  9. mdb_party <- str_replace_all(mdb_party, "CDU/CSU", "cducsu")
  10. mdb_party <- str_replace_all(mdb_party, "Bündnis 90/Die Grünen", "gruene")
  11. mdb_party <- str_replace_all(mdb_party, "Die Linke", "linke")
  12. mdb_party <- str_replace_all(mdb_party, "SPD", "spd")
  13. mdb_list <- data.frame(name = mdb_names, party = mdb_party)
  14. write.csv(mdb_list, "politiker2.csv", row.names=FALSE)
  15. ############
  16. list1 <- read.csv("politiker2.csv")
  17. list2 <- read.csv("politiker.csv")
  18. for(i in 1:nrow(list1)) {
  19. detect <- FALSE
  20. name1 <- as.character(list1$name[i])
  21. lastname1 <- str_extract(name1, "\\w+")
  22. for(a in 1:nrow(list2)) {
  23. name2 <- as.character(list2$name[a])
  24. if(str_detect(name2, lastname1)) {
  25. detect <- TRUE
  26. acc <- as.character(list2$screenname[a])
  27. verif <- as.character(list2$verified[a])
  28. result <- str_c(name1," --> ",acc," (",name2,") ",verif)
  29. write(result, "merge.txt", append = TRUE)
  30. }
  31. }
  32. if(detect) {
  33. write("", "merge.txt", append = TRUE)
  34. }
  35. }