add_col_totals: Add column totals for a set of columns in a dataframe

Description Usage Arguments Value

View source: R/totals.R

Description

Calculates column totals for a set of columns in a dataframe and add them as a new row at the end of the dataframe. A label for the total row is added to each of the columns indicated by the label_col argument. Label columns must be character vectors. NAs are added to any columns not summed or specified as label columns.

Usage

1
2
3
4
5
6
7
8
9
add_col_totals(
  data,
  from = 2,
  to = ncol(data),
  rows = 1:nrow(data),
  na.rm = FALSE,
  label = "total",
  lcols = 1
)

Arguments

data

A dataframe containing columns of numerical data to be summed by column.

from

The number or name of the column from which column totals are calculated. The default is 2, assuming one column for row labels. Use 1 if there are no preceding data columns.

to

The number or name of the column to which column totals are calculated. The default is ncol(data), which means column totals are calculated for all remaining columms in the dataframe.

rows

A numeric vector of the rows to be summed. The default is all rows in the dataframe.

na.rm

A boolean which if TRUE ignores NAs in calculating totals. The default value is FALSE.

label

The label for the totals row. The default is "total".

lcols

A vector or scalar containing the indices of the columns to to which to add the total label. These columns must be character vectors. The default is 1, assuming one column for row labels. Invalid label columns are silently ignored.

Value

A tibble containing the input dataframe with an additional row for column totals.


olihawkins/cltools documentation built on Sept. 14, 2020, 7:25 a.m.