elec_pcts_by_row: elec_pcts_by_row

Description Usage Arguments Details Value Examples

Description

This function lets you select columns in a data frame with raw numbers and will add columns with percent data by row. This is particular useful for election results where each row contains data by precinct, city, etc. and each column is a different candidate, ballot question yes/no, or similar construct.

Usage

1
elec_pcts_by_row(df, mycols, totalcol = "Total")

Arguments

df

data frame that contains at least one numeric column.

mycols

character strings - names of columns with numerical data for which you'd like to calculate percentages across rows.

totalcol

character string - name of column that has vote (or other) totals.

Details

This is a modification of the pct function from the caroline package by David Schruth.

Value

data frame

Examples

1
2
3
4
5
City <- c("Cityville", "Townville", "Placeville")
Yes <- c(250, 100, 150)
No <- c(200, 200, 300)
mydf <- data.frame(City, Yes, No)
mydf$Total <- mydf$Yes + mydf$No

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