Created
March 21, 2020 02:52
-
-
Save lashlee/17ef79ba947cb4604bed31a110421c5a to your computer and use it in GitHub Desktop.
I was curious who gave money to the Persist PAC!
This file contains hidden or 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
# Setup ------------------------------------------------------------------- | |
library(htmltab) | |
library(dplyr) | |
library(ggplot2) | |
library(knitr) | |
library(scales) | |
url <- 'https://docquery.fec.gov/cgi-bin/forms/C00739110/1391696//sa/ALL' | |
# Parse ------------------------------------------------------------------- | |
raw_tab <- htmltab::htmltab( | |
doc = url | |
) | |
tab <- | |
raw_tab %>% | |
setNames( | |
c('name', 'address', 'occupation', 'memo', 'date', 'amount', 'total') | |
) %>% | |
mutate( | |
earmarked = is.na(memo), | |
date = as.Date(date, format = '%m/%d/%Y'), | |
amount = as.numeric(amount), | |
total = as.numeric(total) | |
) %>% | |
select(-memo) %>% | |
arrange(-total) | |
# Results ----------------------------------------------------------------- | |
tab %>% | |
group_by(name, address) %>% | |
summarize(total = sum(amount)) %>% | |
ungroup() %>% | |
mutate(share = total / sum(total)) %>% | |
select(share, total, name, address, total) %>% | |
arrange(-share) %>% | |
mutate(share = percent(share, accuracy = .1), total = dollar(total)) %>% | |
kable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment