sample_nvoters: Take a small sample of voters or precincts

View source: R/utility.R

sample_nvotersR Documentation

Take a small sample of voters or precincts

Description

Custom wrapper around dplyr::sample_n and dplyr::sample_frac. Instead of taking samples of rows, it takes a sample of voters defined by voters (elec, voter_id) or precincts(elec, precinct_id). This is Useful for long-form datasets where each row is an vote for a particular office by a person.

Usage

sample_nvoters(tbl, n)

sample_fvoters(tbl, frac)

sample_nprecincts(tbl, n)

sample_fprecincts(tbl, frac)

Arguments

tbl

the dataset that has the columns elec and voter_id (for sample_nvoters or sample_fvoters) and elec and precinct_id (for sample_nprecincts or sample_fprecincts).

n

Number of voters or precincts to sample

frac

Fraction of voters or precicts to sample. Alternative to n


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