compare_votes: Compare vote totals

Description Usage Arguments Details Value Examples

Description

Compare vote totals with a reference dataset. By default, the reference totals are the state_totals dataset from Dave Leip's Atlas of U.S.Presidential Elections, for candidate values of Donald Trump, Hillary Clinton, Gary Johnson, and "Total" (the sum of votes for these three and all other candidates).

Usage

1
2
compare_votes(.data, reference = NULL, by = c("state_postal", "office",
  "candidate"), all.y = FALSE)

Arguments

.data

Precinct returns dataframe.

reference

A dataframe of reference vote totals. See details.

by

A vector of shared column names in .data and reference to merge on.

all.y

Perform a full join, instead of a left join. This will include in the result all rows from the reference dataset.

Details

We sum votes in each dataframe by the variables specified in argument by, and then left-join .data and the reference dataframe on the same variables.

Value

A copy of .data with state-candidate vote totals and their difference from the reference totals.

Examples

1
2
3
4
5
6
7
8
9
# Use default reference totals from https://uselectionatlas.org
.data = data.frame(office = 'US President', candidate = c('Gary Johnson',
  'Donald Trump'), state_postal = 'AL', votes = c(44000, 1318200))
compare_votes(.data)

# Use an arbitrary dataframe for reference totals
reference = data.frame(office = 'US President', candidate = c('Gary Johnson',
  'Donald Trump'), state_postal = 'AL', votes = c(43022, 1327200))
compare_votes(.data, reference)

MEDSL/medslcleaner documentation built on May 31, 2019, 7:39 a.m.