Guest User

Untitled

a guest
Jan 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. # load required packages via tidyverse
  2. library(tidyverse)
  3.  
  4. # here() used to write csv to correct folder - need to spend time sorting how to use it on file import
  5. library(here)
  6.  
  7. # create a single file of our entire event email distribution (currently 10 separate files)
  8. # import files from data folder and bind - know that all column headers are the same
  9. # shamelessly stolen from stackoverflow
  10. orig_contacts <-
  11. list.files(path = "./data/",
  12. pattern = "*.csv",
  13. full.names = TRUE) %>%
  14. map_df(~read_csv(., col_types = cols(.default = "c")))
  15.  
  16. # what do we have?
  17. names(orig_contacts)
  18.  
  19. # remove unnecessary columns that were added on export
  20. orig_contacts_2 <-
  21. orig_contacts %>%
  22. select(c(FirstName:`TT Participant ID`, Program:District))
  23. names(orig_contacts_2)
  24.  
  25. # Qualtrics tags emails that have been sent with various statuses
  26. # We need to see what's been sent in our 10 distributions, and then filter for email addresses that haven't been opened
  27.  
  28. # distribution history - what's already been sent
  29. distro_hx <-
  30. list.files(path = "./data/sent/",
  31. pattern = "*.csv",
  32. full.names = TRUE) %>%
  33. map_df(~read_csv(., col_types = cols(.default = "c")))
  34.  
  35. # what do we have?
  36. names(distro_hx)
  37. head(distro_hx)
  38.  
  39. # need to sort out what the various categories Qualtrics assigns to each email
  40. distro_hx %>%
  41. group_by(Status) %>%
  42. summarise(n = n())
  43. # categories:
  44. # Email Bounced, Email Sent, Finished Survey, Opted Out,
  45. # Partially Completed Survey, Skipped as Duplicate, Started Survey
  46.  
  47. # creating the new email distribution list
  48. # will need the following columns: Last Name, Status == Email Sent
  49. # need to rename Last Name column to last_name in order to keep embedded data column headers consistent
  50. distro_merge <- distro_hx %>%
  51. rename("last_name" = "Last Name") %>%
  52. select(last_name, Status) %>%
  53. filter(Status == "Email Sent") %>%
  54. inner_join(orig_contacts_2, by = "last_name") %>%
  55. # remove duplicates - semi-redundant, as Qualtrics will also screen duplicates
  56. unique() %>%
  57. select(-Status) %>%
  58. write_csv(here("results", "distro_merge.csv"))
  59.  
  60. names(distro_merge)
Add Comment
Please, Sign In to add comment