x
.
cummax(x) cummin(x)
x
in which the
i
th element is the maximum (resp. minimum)
of the first through the
i
th elements of
x
.
If the first
NA
is
x[j]
, then the
j
th 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)