elec_find_winner: find_winner

Description Usage Arguments Details Value Examples

Description

This function finds the top vote-getter in a csv or Excel election results file - it looks for the largest number in each row and creates a new column with the name of the winner(s) (more specifically, the column name with the maximum value for each row). Accounts for ties. Requires rio package.

Usage

1
elec_find_winner(filename, datacolstart, datacolstop, exportcsv = TRUE)

Arguments

filename

string name of file, either spreadsheet or csv, including extension and file path if not in your working directory. If name does not include ".csv", ".tsv", ".xlsx", ".xls", or ".ods", function assumes that you want to use the name of a data frame that already exists in your working environment.

datacolstart

integer number of the column where the results data starts. If data starts in column B of an Excel spreadsheet, for example, datacolstart should be 2.

datacolstop

integer number of the column where the results data ends

exportcsv

Boolean If you want results saved to a csv file (name is same as filename_winners.csv)

Details

Results file must have candidate results in adjoining columns, in a format with each candidate having their own column of results. findwinner function arguments: filename (string), datacolstart (number of data column where results data starts; 2 for column B in Excel, for example), datacolstop (number of the last dat…

Value

dataframe

Examples

1
2
3
4
## Not run: 
mydata <- find_winner("results.xlsx", 2, 4)

## End(Not run)

smach/rmiscutils documentation built on Dec. 15, 2021, 1:49 a.m.