Description Usage Arguments Examples
add a summary row to a data frame
1 2 |
df |
the data frame |
cols |
numeric vector of columns to include in the summary row |
fun |
function to summarize data frame rows |
... |
other arguments to be passed to the function specified in the fun argument |
rows |
numeric vector of rows to include in summary calculation. By default
|
label_col |
column number to hold the summary row label specified by
the |
label |
summary row label (e.g. "Totals") |
new_row |
boolean value indicating whether the summary row should be a new row attached to the bottom of the data frame or if it should be combined with an already existing summary row. |
fill |
value to insert in columns not specified in the |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | df <- data.frame("year" = 2014:2016,
"a" = c(NA, 1, 3),
"b" = c("g", "e", "f")
)
summary_row(fun = sum, na.rm = TRUE, df = df, cols = 2)
summary_row(fun = sum, na.rm = TRUE, df = df, cols = 2, label_col = 1,
label = "Totals")
summary_row(fun = sum, na.rm = TRUE, df = df, cols = 2, fill = "HI")
df$d <- 5:7
# add new row
df <- summary_row(fun = sum, na.rm = TRUE, df = df, cols = c(2, 4),
label_col = 1, label = "Totals")
# adjust newest row
df <- summary_row(fun = mean, na.rm = TRUE, df = df, cols = c(2, 4),
label_col = 1, label = "Averages")
# I didn't want the mean in column 4, I actually wanted the product
df <- summary_row(fun = prod, na.rm = TRUE, df = df, cols = 4, label_col = 1,
label = "Averages/Products", new_row = FALSE)
# new cummary row with the average of the last 2 years
summary_row(fun = mean, df = df, cols = c(2, 4), rows = 2:3, label_col = 1,
label = "2 Yr AVG")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.