Skip to content

Instantly share code, notes, and snippets.

@jrnold
Created March 26, 2016 05:06
Show Gist options
  • Save jrnold/87aff4e7bcf7d3986d26 to your computer and use it in GitHub Desktop.
Save jrnold/87aff4e7bcf7d3986d26 to your computer and use it in GitHub Desktop.
Get all polls from the 2016 election cycle from Pollster API using the R package pollstR
library("pollstR")
library("dplyr")
# Get the list of available charts
charts <- pollstr_charts()
# Filter charts for any chart matching 2016
charts_2016_slugs <- grep("^2016", charts$charts$slug, value = TRUE)
charts_2016_slugs %>% head()
# These can be used when querying charts or polls
# Get all charts for the the 2016 election cycle
all_charts_2016 <- lapply(charts_2016_slugs, function(slug) {
pollstr_polls(chart = slug)
})
# Get all polls for the the 2016 election cycle
all_polls_2016 <- lapply(charts_2016_slugs,
function(slug) {
pollstr_chart(chart = slug)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment