totals_row: totals_row

Description Usage Arguments Examples

View source: R/summary-row.R

Description

add a totals summary row to a data frame. This is a wrapper around the summary_row function.

Usage

1
2
totals_row(df, cols, rows = NA, label_col = NA, label = "Totals",
  new_row = TRUE, fill = NA)

Arguments

df

the data frame

cols

numeric vector of columns to include in the summary row

rows

numeric vector of rows to include in summary calculation. By default rows is set to all rows that were not created by the a summary_row function.

label_col

column number to hold the summary row label specified by the label argument

label

summary row label. defaults to "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 cols argument. Default is NA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
df <- data.frame("year" = 2014:2016,
                 "a" = c(NA, 1, 3),
                 "b" = c("g", "e", "f")
      )

totals_row(df = df, cols = 2)
totals_row(df = df, cols = 2, label_col = 1, label = "Totals")

df$d <- 5:7

# add new row
totals_row(df = df, cols = c(2, 4), label_col = 1, label = "Totals")

merlinoa/summaryrow documentation built on May 22, 2017, 4:16 a.m.