r - Finding local maxima and minima -
i'm looking computationally efficient way find local maxima/minima large list of numbers in r. without for
loops...
for example, if have datafile 1 2 3 2 1 1 2 1
, want function return 3 , 7, positions of local maxima.
diff(diff(x))
(or diff(x,differences=2)
: @zheyuanli) computes discrete analogue of second derivative, should negative @ local maxima. +1
below takes care of fact result of diff
shorter input vector.
edit: added @tommy's correction cases delta-x not 1...
tt <- c(1,2,3,2,1, 1, 2, 1) which(diff(sign(diff(tt)))==-2)+1
my suggestion above ( http://finzi.psych.upenn.edu/r/library/ppc/html/ppc.peaks.html ) intended case data noisier.
Comments
Post a Comment