cummax
Cumulative Maxima and Minima

Description

Returns a vector of non-decreasing (resp. non-increasing) numbers that are the cumulative maxima (resp. minima) of the values in x.

Usage

cummax(x) 
cummin(x)

Arguments

x a numeric vector.

Missing values (NA) are allowed.

Details

If the first NA is x[j], then the jth and all following elements of the result are NA.
These are members of the Math group of generic functions.
When x is a matrix object, x is converted to a vector according to column first order. When x is a data frame object, the function applies only on each row.
Value
returns a vector like x, in which the ith element is the maximum (resp. minimum) of the first through the ith elements of 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
cumsum, max, pmax.
Examples
# compute times between subsequent maxima 
set.seed(30)		#set the .Random.seed 
x <- rnorm(100) 
xm <- cummax(x) 
diff((2:100)[xm[2:100]>xm[1:99]]) # returns c(5, 19, 41) 
Package base version 6.0.0-69
Package Index