[Rd] inconsistency in return value of peaks() {splus2R} (PR#13988)

vijgh at phil.uu.nl vijgh at phil.uu.nl
Wed Oct 7 12:15:10 CEST 2009

Full_Name: Benny van der Vijgh
Version: 2.7.2
OS: Windows Vista
Submission from: (NULL) (

The return value of peaks() in package splus2R is not consistent. 
This is because of the call to max.col() without additional parameters which
peaks() makes.
max.col() has a parameter 'ties.method' which specifies how ties are handled,
with "random" by default. 
This means that when peaks() is called on a vector with two (or more)
neighbouring elements in a tie for the local maximum, these end up in the same
row in the embedded matrix after which max.col() at random chooses which will be
considered the maximum, thereby yielding inconsistent results, for example:

> a <- c(3,5,5,3)
> peaks(a)
> peaks(a)

this can be easily fixed by setting the parameter 'ties.method' for max.col() to
"first" or "last", which is a matter of application and taste I think, perhaps
it can even be considered to make this parameter also a parameter of peaks() and
pass it to max.col() in the execution.

More information about the R-devel mailing list