cast_to_wide: long voter-vote to voter-based data

View source: R/reshaping.R

cast_to_wideR Documentation

long voter-vote to voter-based data

Description

This drops offices where multiple votes are cast for the same contest_code. This is necessary to make a voter uniquely identify a vote for a contest (column). Some offices like congress and state leg are separated out into district-name pairs, with a specific column for a district and the vote in that corresponding district. Absentees are also dropped because they do not have precint information.

Usage

cast_to_wide(
  df = raw,
  contests = c("PTY", "PRS", "USH", "USS", "GOV", "LGV", "SOS", "ATG", "SSI", "HOU",
    "SEN", "JPR", "SHF", "COR", "CLR", "AUD", "CTR", "CCL", "CCD", "CCA", "CCC", "SCH",
    "WAT", "Q", "LRCA")
)

Arguments

df

A standardized long dataset with contest_code and contest_name. Should have the variables elec, county, contest_code, voter_id,, precinct, precinct_id.

contests

A vector of contest_codes to select and put into the wide.

Value

A dataset at the individual voter level. For some offices with a district, these are collapsed to a pair-district pairing. If a voter abstained the _vote variable is NA (indeed it was not in the long dataset), but we try to impute the district by the voter's precinct and ballot style.


kuriwaki/ballot documentation built on May 1, 2023, 9:55 p.m.