Skip to content
Prev 387609 / 398502 Next

local maxima positions in a vector with duplicated values

Using rle() may make it easier - finding the peak values is easier and
select from cumsum(lengths) to get the positions of the last values
before the peaks, then add 1.  I have not tested the following very
much.

function(x) {
  rx <- rle(x)
  cumsum(rx$lengths)[c(diff(diff(rx$values)>0) == -1,FALSE,FALSE)]+1
}

-Bill

On Fri, Mar 26, 2021 at 8:36 AM Stefano Sofia
<stefano.sofia at regione.marche.it> wrote: