cumsum_by: Cumulative sums for database lists

Description Usage Arguments Value

View source: R/cumsum_by.R

Description

Observations needing the calculation of a cumulative sum, for instance in germination experiments, will require to be done by treatment, combining identifiers (e.g. treatment and repetition).

In the formula method you set in the left term the numeric variable which has to be acummulated. Note that you can insert in the left term multiple variables separating them by a plus symbol ('+'). On the right term you set the sorting variable (usually time, Date or integer) as the first term followed by identifiers.

This function is checking the uniqueness of the temporal variable per treatment. For ties the function will retrieve an error message.

Usage

1
2
3
4
5
6
7
cumsum_by(x, ...)

## S3 method for class 'data.frame'
cumsum_by(x, ids, vars, by, suffix = "_cumul", diff = FALSE, ...)

## S3 method for class 'formula'
cumsum_by(x, data, ...)

Arguments

x

A data frame containing or a formula, depending on the method. See the description above to design the formula.

...

Further arguments passed among methods.

ids

A character vector with the names of the variables used to identify every experimental object (usually the combination of treatment and repetition).

vars

A character vector with the names of the variables used to calculate the cumulative sum.

by

A character value used as temporal variable.

suffix

A character value added to the name of the variable in the output data frame.

diff

A logical value. If true, the lagged differences (function diff()) instead of the cumulative sums (function cumsum()) will be calculated.

data

A data frame required in the formula method.

Value

The input data frame with the cumulative sums as additional variables. Note that the sorting of rows may change in the process.


kamapu/cropgrowth documentation built on Aug. 22, 2021, 8:55 a.m.