Cumulative Maxima and Minima

DESCRIPTION:

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

USAGE:

cummax(x) 
cummin(x) 

REQUIRED ARGUMENTS:

x
a numeric vector. Missing values (NA) are allowed.

VALUE:

a vector like x in which the ith element is the maximum (resp. minimum) of the first through the ith elements of x.

DETAILS:

If the first NA is x[j], then the jth and all following elements of the result will be NA.

SEE ALSO:

, , , .

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)