-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-created create_dist-level-data_2022-2024.R to create cd_info_2006 and cd_info_2012 -fixed cd_info_2022 to match documentation -added sources to datadoc_cd-info
- Loading branch information
1 parent
af4e095
commit d249d2e
Showing
6 changed files
with
65 additions
and
27 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
library(tidyverse) | ||
library(googlesheets4) | ||
|
||
# Authenticate with Google Sheets | ||
gs4_auth() | ||
|
||
# URLs for your Google Sheets | ||
url_2006 <- "https://docs.google.com/spreadsheets/d/1l7W130tPRF6dQ4JoqlQJSJexnEg4rZct-7kwDXqgoLE/edit?gid=429358610#gid=429358610" | ||
url_2012 <- "https://docs.google.com/spreadsheets/d/1xn6nCNM97oFDZ4M-HQgoUT3X4paOiSDsRMSuxbaOBdg/edit?gid=0#gid=0" | ||
|
||
# Read data from Google Sheets | ||
|
||
# 2006 | ||
cd_names_2006 <- read_sheet(url_2006, range = "A2:E", col_names = TRUE, sheet = 1) |> | ||
mutate(year = 2006) |> | ||
select(year, cd = CD) | ||
|
||
voting_info_2006 <- read_sheet(url_2006,range = "A2:I", col_names = TRUE, sheet = 2) |> | ||
select(cd = CD, | ||
pct_mccain = 'McCain%') | ||
|
||
# 2012 | ||
cd_names_2012 <- read_sheet(url_2012, range = "A2:G", col_names = TRUE, sheet = 1) |> | ||
mutate(year = 2012) |> | ||
select(year, cd = CD) | ||
|
||
voting_info_2012 <- read_sheet(url_2012, range = "A2:O", col_names = TRUE, sheet = 2) |> | ||
select(cd = CD, | ||
presvotes_total = 7, | ||
pct_romney = 'Romney%', | ||
pct_mccain = 'McCain%') | ||
|
||
# Join data from page 1 and page 2 for each dataset | ||
cd_info_2006 <- cd_names_2006 |> | ||
left_join(voting_info_2006, by = "cd") |> | ||
mutate(cd = str_replace(cd, "-AL$", "-01")) | ||
|
||
cd_info_2012 <- cd_names_2012 |> | ||
left_join(voting_info_2012, by = "cd") |> | ||
mutate(cd = str_replace(cd, "-AL$", "-01")) | ||
|
||
# Save the data | ||
usethis::use_data(cd_info_2022, overwrite = TRUE) | ||
usethis::use_data(cd_info_2024, overwrite = TRUE) |
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
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.