Created
March 26, 2016 05:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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