x.
cummax(x) cummin(x)
x in which the
ith element is the maximum (resp. minimum)
of the first through the
ith elements of
x.
If the first
NA is
x[j], then the
jth and all following elements of the
result will be
NA.
# 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)