Description Usage Arguments Details Value Examples
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.
1 | elec_pcts_by_row(df, mycols, totalcol = "Total")
|
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. |
This is a modification of the pct function from the caroline package by David Schruth.
data frame
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.