which.peaks function

Find local maxima and minima in a sequence