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

1
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

1
2
3
4
library(dplyr) # for the %>% pipe
mtcars %>%
  crosstab(am, cyl) %>%
  add_totals_row

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.