Skip to content
Prev 387639 / 398502 Next

local maxima positions in a vector with duplicated values

Dear Bill, Bert, Greg and Abby,
I tested your code (honestly apart from Abby's solution because it needed an additional package and I run R in a server which is not administrated by myself), they work and I found them equivalent. (Probably Bill's and Greg's solutions are a bit faster than Bert's.)

In my real application I found a case where none of them work: when the series is monotonic. In this case the last number of the vector (or the last duplicated numbers) is not a maximum but it is anyway the highest number of the vector:
The error is: argument is of length zero.
Your code is at the moment too complicated for me to modify. I ask if there is an "easy" extension of the code that you kindly wrote for me to handle also this possibility.

Thank you for everything
Stefano



         (oo)
--oOO--( )--OOo--------------------------------------
Stefano Sofia PhD
Civil Protection - Marche Region - Italy
Meteo Section
Snow Section
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona (AN)
Uff: +39 071 806 7743
E-mail: stefano.sofia at regione.marche.it
---Oo---------oO----------------------------------------