Richard Sprague

Mercer Island local election results

How to calculate Mercer Island precinct-level 2020 presidential election results using R and King County CSV data.

National and local news outlets report the results of the Presidential election at the state and county level, but that doesn’t tell me how my neighborhood voted. For that I’ll need the precinct-by-precinct results, which in my area is not reported. Can I calculate it myself? Here’s how.

First you obtain the full King County election results as a precinct-by-precint CSV file and read that into the variable election2020. Although preliminary precinct-level results are posted on election night, the analysis below uses the final numbers that were published November 24th.

Filter the results to look for just the Mercer Island precincts, and further narrow down to just the US Presidential results.

Code
mercerIsland2020<- election2020 %>% dplyr::filter(grepl("M-I",as.character(Precinct))) %>% 
  select(Race,Precinct, CounterType, SumOfCount) %>% tibble()


mi.president.all<-dplyr::filter(mercerIsland2020,grepl("US",Race))   %>% 
  dplyr::select(precinct=Precinct,candidate=CounterType,sum=SumOfCount)

mi.president.all %>% dplyr::filter(candidate!="Times Counted" &
                              candidate!="Registered Voters") %>%
  dplyr::group_by(candidate) %>% 
  dplyr::summarize(sum=sum(sum)) %>%
  dplyr::arrange(desc(sum)) %>%
  dplyr::mutate(pct=sum/sum(sum)*100) %>%
  knitr::kable(digits=3)

Top Candidates

Sometimes it’s nice to compare just among votes case for the “top candidates”, like this:

Code
topCandidates<-c("Donald J. Trump and Michael R. Pence",
                 "Jo Jorgensen and Jeremy \"Spike\" Cohen",
                 "Joseph R. Biden and Kamala D. Harris")

mi.president<-mi.president.all %>% dplyr::filter(candidate %in% topCandidates)
mi.president$candidate<-factor(mi.president$candidate)

mi.president.top<-mi.president %>% dplyr::group_by(candidate) %>%
  dplyr::summarize(sum=sum(sum)) %>%
  dplyr::arrange(desc(sum)) %>%
  dplyr::mutate(pct=sum/sum(sum)*100)

knitr::kable(mi.president.top,digits=3)

You can compare with the Mercer Island 2016 Results

and that’s it!

TechnologyMercer Island

Keep reading

Mask-Wearing: How to Lie With Statistics

How the same COVID-19 data can prove opposite conclusions about mask mandates, demonstrating chart manipulation and statistical bias.

Aggregating Mercer Island local election results

Using R to analyze 2016 presidential election results by precinct on Mercer Island from King County data.

Test Driving the Miles Electric Car

Mike Cero, always looking for cost-effective ways to help the environment , invited me to help test drive an electric car now available for sale from MC Electric…

Search