Skip to contents

Computes aggregate statistics for a data frame of election results. The state is detected automatically from the state column when present, or from the variable name (e.g. ga_results -> "Georgia").

Usage

summarize_results(df, state = NULL)

Arguments

df

A data frame returned by scrape_elections.

state

Optional two-letter state abbreviation or full state name. Overrides auto-detection when supplied.

Value

A named list (printed on call) with:

state

Detected or supplied state name.

years

Integer vector of election years present.

n_years

Number of distinct election years.

n_elections

Number of distinct elections.

n_candidates

Number of distinct candidate names.

office_level_breakdown

Named integer vector: distinct elections by level (Federal / State / Local).

offices_by_level

Named list: distinct office names per level.

Examples

# \donttest{
ga_results <- scrape_elections("GA", 2020, 2024)
#> Error: Scraping failed for Georgia (GA Secretary of State).
#> 
#>   Error: Python environment 'downballotR' does not exist.
#> Run downballots_install_python() first.
#> 
#>   If this looks like a bug or the data source may have changed,
#>   please file a report (including the error above) at:
#>   https://github.com/gchickering21/DownBallotR/issues
summarize_results(ga_results)
#> Error: object 'ga_results' not found
# }