Another approach that involves more infrastructure is to fit a smooth line to your points, compute the first derivative, and look for change in sign in the first derivative.
eg x <- c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12) smoothed.dx <- predict(smooth.spline(x), deriv=1)$y which(c(smoothed.dx,NA) > 0 & c(NA, smoothed.dx) < 0) My experience is that this approach sometimes requires some fine-tuning, eg in fitting the smooth. I hope that this helps Andrew On Mon, Mar 24, 2008 at 11:23:57PM -0400, Research Scholar wrote: > Hi > Thanks for replying. I meant x[4] is the start of a peak shape and x[14] is > the end of that peak and x[9] is the maxima of the peak. > Thanks, > John > > > > > On Mon, Mar 24, 2008 at 11:09 PM, <[EMAIL PROTECTED]> wrote: > > > It's hard to see how positions 4 and 14 correspond to 'peaks', they look > > like troughs to me. So perhaps this is what you mean: > > > > > x <- c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12) > > > > > y <- which(x == min(x)) > > > y > > [1] 4 14 > > > > as a function: > > > > somefunction <- function(x) which(x == min(x)) > > > > > > Bill Venables > > CSIRO Laboratories > > PO Box 120, Cleveland, 4163 > > AUSTRALIA > > Office Phone (email preferred): +61 7 3826 7251 > > Fax (if absolutely necessary): +61 7 3826 7304 > > Mobile: +61 4 8819 4402 > > Home Phone: +61 7 3286 7700 > > mailto:[EMAIL PROTECTED] > > http://www.cmis.csiro.au/bill.venables/ > > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > On Behalf Of Research Scholar > > Sent: Tuesday, 25 March 2008 12:54 PM > > To: r-help@r-project.org > > Subject: [R] peak finding > > > > Hi all > > Is there a function that can find the start and end position of peaks > > in a > > set of numbers. > > eg. > > x <- c(14,15,12,11,12,13,14,15,16,15,14,13,12,11,14,12) > > y <- somefunction(x) > > > > y > > 4 14 > > > > > > Thanks > > John > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.