Cumulative Sums and Products

DESCRIPTION:
Returns an object which, for each element, is the sum of all of the elements to that point.

USAGE:
cumsum(x)
cumprod(x)

REQUIRED ARGUMENTS:
x:
numeric or complex object.
Missing values (NA) are allowed.

VALUE:
object like x whose i-th value is the sum or product of the first i values in x.

CLASSES:
This function will be used as the default method for classes that do not inherit a specifc method for the function or for the Math group of functions. The result will retain 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.

DETAILS:
If the first NA in x is x[j], the j-th and all following elements of the value will be NA. A warning message is printed if NAs are generated.

These are members of the Math group of generic functions.

The cumprod function performs arithmetic in double precision even if x has integer storage mode.


SEE ALSO:
cummax , Arithmetic .

EXAMPLES:
cumsum(1:6) # returns c(1, 3, 6, 10, 15, 21)

cumprod(1:6) # returns c(1, 2, 6, 24, 96, 576)