addCumSums: Add cumulative sums (standard and normalized) of a column to...

View source: R/addCumSums.R

addCumSumsR Documentation

Add cumulative sums (standard and normalized) of a column to a dataframe by an index and set of factors

Description

Function to add cumulative sums (standard and normalized) of a column to a dataframe by an index column and set of factor columns.

Usage

addCumSums(dfr, valCol, idxCol = NULL, factors = NULL, verbose = FALSE)

Arguments

dfr
  • dataframe (or object that can be coerced to a dataframe) with values column to be cum-summed, index column, and factor levels

valCol
  • name of values column to be cum-summed (as character string; e.g., "num")

idxCol
  • name of "index" column to track cum-summing (as character string; e.g. "size", or NULL if none)

factors
  • vector of names of columns in dfr to serve as factors in the summations (or NULL)

verbose
  • flag (T/F) to print diagnostic information

Details

Uses sqldf.

Value

a dataframe of results with columns corresponding to the factors, the index column (if defined), the values column, a "nrmlzd" column, a "cumSum" column, and a "nrmSum" column. The latter three represent the normalized values (summing to 1), the cumulative sum of the values, and the cumulative sum of the normalized values, where the normalization and sums are taken over each factor combination and the associated index set.


wStockhausen/wtsUtilities documentation built on March 16, 2024, 10:38 a.m.