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").
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:
stateDetected or supplied state name.
yearsInteger vector of election years present.
n_yearsNumber of distinct election years.
n_electionsNumber of distinct elections.
n_candidatesNumber of distinct candidate names.
office_level_breakdownNamed integer vector: distinct elections by level (Federal / State / Local).
offices_by_levelNamed 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
# }