Message-ID: <1193769.1616783260-6801@apollo2.minshall.org>
Date: 2021-03-26T18:27:40Z
From: Greg Minshall
Subject: local maxima positions in a vector with duplicated values
In-Reply-To: Your message of "Fri, 26 Mar 2021 15:35:37 +0000." <8B435C9568170B469AE31E8891E8CC4FC658BA79@ESINO.regionemarche.intra>
Stefano,
my contribution is similar to Bill Dunlap's:
x <- c(1,0,0,0,2,2,3,4,0,1,1,0,5,5,5,0,1)
(cumsum(rle(x)$lengths)-(rle(x)$length-1))[which(diff(diff(rle(x)$values)>=0)<0)+1]
cumsum(rle(x)$lengths)[which(diff(diff(rle(x)$value)>0)>0)+1]
kind of a cute little problem, actually.
cheers, Greg