Giter Site home page Giter Site logo

ballot's People

Contributors

kuriwaki avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ballot's Issues

std_race() takes too long

a better way to do this office-by-office recoding more quickly?

ballot/R/format_values.R

Lines 1 to 102 in 1f75e4e

#' Standardize race variables to proper names with leading 7-character codes
#'
#' @param vec Vector of unstandardized race names
#'
#' @export
#'
#' @examples
#' vec <- c("CON0001 House 1", "CONG007 House 7", "U. S. Senator", "CCNL001 Council 1", "CCD0001 Council 1")
#' std_race(vec)
#'
std_race <- function(vec) {
prs_regex <- "President.*"
pty_regex <- "Straight Party"
none_regx <- ".*NO VOTES CAST.*"
# One per state
gov_regex <- "^Governor"
ltg_regex <- "^(Lieutenant|Lt) Governor"
atg_regex <- "^Attorney General"
sos_regex <- "Secretary of State"
sad_regex <- "^Auditor"
adj_regex <- "^Adjutant General"
str_regex <- "^State Treasurer"
cmp_regex <- "^Comp(tr|rt)oller General"
ssi_regex <- "^State Superintendent.*"
agr_regex <- "^Commissioner of Agri.*"
# One per County or one per several counties level
cad_regex <- "County Auditor"
ctr_regex <- "^County Treasurer"
cor_regex <- "Coroner"
shf_regex <- "^Sheriff"
clr_regex <- "(County )?Clerk of Court"
jpr_regex <- "^Probate Judge"
ccc_regex <- "County Council Chair"
cal_regex <- "County Council At Large"
rgd_regex <- "Register of Deeds"
rmc_regex <- "Register of Mesne Convey(a|e)nce"
ccl1_regx <- "^C(CN|NC)L" # standardize CCNL to CCL
ccl2_regx <- "^CCD" # standardize CCD to CCL
hou_regex <- "^HOUS" # standardize HOUS to HOU0
# multiple votes per person
wat_regex <- "Soil and Water.*"
# Federal
h01_regex <- "CON(G|0)001.*"
h02_regex <- "CON(G|0)002.*"
h03_regex <- "CON(G|0)003.*"
h04_regex <- "CON(G|0)004.*"
h05_regex <- "CON(G|0)005.*"
h06_regex <- "CON(G|0)006.*"
h07_regex <- "CON(G|0)007.*"
sen_regex <- "^U\\.?\\s?S\\.? Senat(e|or)$"
sn2_regex <- "^U\\.?\\s?S\\.? Senat(e|or) \\(Unexpired Term\\)"
inner <- function(input, regex_str, replacement) {
str_replace(input, regex(regex_str, ignore_case = TRUE), replacement)
}
vec %>%
inner(prs_regex, "PRS0000 President") %>%
inner(pty_regex, "PTY0000 Straight Party") %>%
inner(none_regx, "A000000 Absentee for all Offices") %>%
inner(gov_regex, "GOV0000 Governor") %>%
inner(ltg_regex, "LGV0000 Lieutenant Governor") %>%
inner(sos_regex, "SOS0000 Secretary of State") %>%
inner(sad_regex, "AUD0000 Auditor") %>%
inner(atg_regex, "ATG0000 Attorney General") %>%
inner(adj_regex, "ADJ0000 Adjutant General") %>%
inner(str_regex, "STRES00 State Treasurer") %>%
inner(cmp_regex, "CMP0000 Comptroller General") %>%
inner(ssi_regex, "SSI0000 State Superintendent of Education") %>%
inner(agr_regex, "AGR0000 State Commissioner of Agriculture") %>%
inner(cad_regex, "CAUD000 County Auditor") %>%
inner(ctr_regex, "CTRES00 County Treasurer") %>%
inner(cor_regex, "COR0000 Coroner") %>%
inner(shf_regex, "SHF0000 Sheriff") %>%
inner(clr_regex, "CLR0000 Clerk of Court") %>%
inner(jpr_regex, "JPRB000 Probate Judge") %>%
inner(ccl1_regx, "CCL0") %>%
inner(ccl2_regx, "CCL") %>%
inner(ccc_regex, "CCL0000 County Coucil Chair") %>%
inner(cal_regex, "CCL0000 County Coucil at Large") %>%
inner(hou_regex, "HOU0") %>%
inner(rgd_regex, "RGD0000 Register of Deeds") %>%
inner(rmc_regex, "RMC0000 Register of Mesne Conveyance") %>%
inner(wat_regex, "WAT0000 Soil and Water District Commissioner") %>%
inner(h01_regex, "USHOU01 US House SC-01") %>%
inner(h02_regex, "USHOU02 US House SC-02") %>%
inner(h03_regex, "USHOU03 US House SC-03") %>%
inner(h04_regex, "USHOU04 US House SC-04") %>%
inner(h05_regex, "USHOU05 US House SC-05") %>%
inner(h06_regex, "USHOU06 US House SC-06") %>%
inner(h07_regex, "USHOU07 US House SC-07") %>%
inner(sen_regex, "USSEN01 US Senator") %>%
inner(sn2_regex, "USSEN02 US Senator (Special)")
}

add to EL155 row removal based on cross-check with shell line count

About 56 counties where counts of votes don't match (diff)

library(tibble)
off_counties <-  tribble(
  ~elec,           ~county,        ~lines_orig, ~lines,   ~voters_orig, ~voters, ~diff, 
  "SC_2014-11-04", "Charleston",   2053129L,    2087477L, 93183L,       93184L,  34349L,
  "SC_2012-11-06", "Charleston",   1797334L,    1827410L, 145737L,      145738L, 30077L,
  "SC_2012-11-06", "Horry",        1143572L,    1162095L, 105380L,      105381L, 18524L,
  "SC_2012-11-06", "Dorchester",   767831L,     780259L,  52966L,       52967L,  12429L,
  "SC_2014-11-04", "Georgetown",   352650L,     364452L,  19598L,       19599L,  11803L,
  "SC_2014-11-04", "Dorchester",   570627L,     579883L,  33068L,       33069L,  9257L, 
  "SC_2014-06-10", "Charleston",   209867L,     217093L,  26610L,       26611L,  7227L, 
  "SC_2014-11-04", "Greenwood",    284587L,     289360L,  16525L,       16526L,  4774L, 
  "SC_2014-06-10", "Horry",        226986L,     230720L,  23644L,       23645L,  3735L, 
  "SC_2014-11-04", "Marion",       151155L,     153644L,  8350L,        8351L,   2490L, 
  "SC_2013-05-07", "Charleston",   61380L,      63578L,   61380L,       61381L,  2199L, 
  "SC_2016-02-20", "Charleston",   53194L,      55176L,   53194L,       53195L,  1983L, 
  "SC_2016-02-27", "Greenville",   30445L,      32224L,   30445L,       30446L,  1780L, 
  "SC_2016-06-28", "Greenville",   47570L,      49338L,   30473L,       30474L,  1769L, 
  "SC_2012-01-21", "Charleston",   46009L,      47743L,   46009L,       46010L,  1735L, 
  "SC_2016-11-08", "Marlboro",     100896L,     102535L,  9441L,        9442L,   1640L, 
  "SC_2016-02-27", "Charleston",   38309L,      39793L,   38309L,       38310L,  1485L, 
  "SC_2012-01-21", "Richland",     34571L,      35857L,   34571L,       34572L,  1287L, 
  "SC_2013-03-19", "Charleston",   30128L,      31280L,   30128L,       30129L,  1153L, 
  "SC_2016-02-20", "Horry",        53566L,      54497L,   53566L,       53567L,  932L,  
  "SC_2014-06-24", "Charleston",   17108L,      17886L,   9552L,        9553L,   779L,  
  "SC_2013-04-02", "Charleston",   18023L,      18775L,   18023L,       18024L,  753L,  
  "SC_2012-06-12", "Charleston",   11180L,      11778L,   7438L,        7439L,   599L,  
  "SC_2013-05-07", "Dorchester",   20218L,      20571L,   20218L,       20219L,  354L,  
  "SC_2014-06-24", "Horry",        15593L,      15918L,   7445L,        7446L,   326L,  
  "SC_2013-10-01", "Charleston",   7364L,       7682L,    7364L,        7365L,   319L,  
  "SC_2012-07-17", "Charleston",   5910L,       6176L,    5910L,        5911L,   267L,  
  "SC_2011-04-12", "Lancaster",    3811L,       4057L,    3811L,        3812L,   247L,  
  "SC_2014-06-24", "Marlboro",     3995L,       4226L,    2181L,        2182L,   232L,  
  "SC_2014-06-24", "Chesterfield", 13031L,      13255L,   6546L,        6547L,   225L,  
  "SC_2013-08-13", "Charleston",   4629L,       4851L,    4629L,        4630L,   223L,  
  "SC_2013-08-27", "Charleston",   4173L,       4371L,    4173L,        4174L,   199L,  
  "SC_2013-03-19", "Dorchester",   10055L,      10246L,   10055L,       10056L,  192L,  
  "SC_2012-01-21", "Georgetown",   9563L,       9745L,    9563L,        9564L,   183L,  
  "SC_2016-06-14", "Marlboro",     9651L,       9815L,    4185L,        4186L,   165L,  
  "SC_2012-09-18", "Charleston",   3191L,       3347L,    3191L,        3192L,   157L,  
  "SC_2012-10-02", "Charleston",   3191L,       3347L,    3191L,        3192L,   157L,  
  "SC_2012-05-29", "Charleston",   2718L,       2872L,    2718L,        2719L,   155L,  
  "SC_2013-04-02", "Dorchester",   6971L,       7115L,    6971L,        6972L,   145L,  
  "SC_2016-06-28", "Jasper",       8018L,       8156L,    4755L,        4756L,   139L,  
  "SC_2012-01-21", "Marion",       2235L,       2331L,    2235L,        2236L,   97L,   
  "SC_2016-02-20", "Marlboro",     1728L,       1806L,    1728L,        1729L,   79L,   
  "SC_2016-06-28", "Horry",        3611L,       3683L,    2683L,        2684L,   73L,   
  "SC_2011-04-12", "York",         1449L,       1519L,    1449L,        1450L,   71L,   
  "SC_2012-06-12", "Chesterfield", 2826L,       2887L,    2709L,        2710L,   62L,   
  "SC_2013-02-05", "Greenville",   2522L,       2574L,    2522L,        2523L,   53L,   
  "SC_2015-10-20", "Charleston",   942L,        992L,     942L,         943L,    51L,   
  "SC_2015-09-15", "Charleston",   969L,        1015L,    969L,         970L,    47L,   
  "SC_2014-11-04", "Marlboro",     100064L,     100110L,  5455L,        5455L,   46L,   
  "SC_2016-02-27", "Marlboro",     2280L,       2325L,    2280L,        2281L,   46L,   
  "SC_2015-09-01", "Charleston",   813L,        855L,     813L,         814L,    43L,   
  "SC_2012-11-06", "Cherokee",     143947L,     143977L,  20402L,       20402L,  30L,   
  "SC_2013-03-12", "Greenville",   826L,        841L,     826L,         826L,    15L,   
  "SC_2014-09-02", "Horry",        169L,        176L,     169L,         170L,    8L,    
  "SC_2013-10-01", "Dorchester",   112L,        114L,     112L,         113L,    3L,    
  "SC_2013-08-27", "Dorchester",   41L,         42L,      41L,          42L,     2L
)
``

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.