Learn R Programming

janitor (version 0.2.1)

add_totals_row: Append a totals row to a data.frame.

Description

This function excludes the first column of the input data.frame, assuming that it contains a descriptive variable not to be summed.

Usage

add_totals_row(dat, na.rm = TRUE)

Arguments

dat
an input data.frame with numeric values in all columns beyond the first.
na.rm
should missing values (including NaN) be omitted from the calculations?

Value

Returns a data.frame with a totals row, consisting of "Total" in the first column and column sums in the others.

Examples

Run this code
library(dplyr) # for the %>% pipe
mtcars %>%
  crosstab(am, cyl) %>%
  add_totals_row

Run the code above in your browser using DataLab