cumsum
Cumulative Sums and Products

Description

Returns an vector that is the cumulative sums or products of all of the elements to that point for each element.

Usage

cumsum(x) 
cumprod(x)

Arguments

x a numeric or complex object. Missing values (NAs) are allowed.

Details

If the first NA in x is x[j], the j-th and all following elements of the value are NA.
cumsum and cumprod are members of the Math group of generic functions.
The cumprod function performs arithmetic in double precision, even if x has integer storage mode.
Value
returns an object like x, whose i-th value is the sum or product of the first i values in x.
Classes
This function is used as the default method for classes that do not inherit a specific method for the function or for the Math group of functions. The result retains the class and the attributes. If this behavior is not appropriate, the designer of the class should provide a method for the function or for the Math group.
See Also
cummax, sum, Arithmetic.
Examples
cumsum(1:6) # returns c(1, 3, 6, 10, 15, 21) 
cumprod(1:6) # returns c(1, 2, 6, 24, 120, 720) 

Package base version 6.0.0-69
Package Index