[R] find inflexion point of discrete value list with R

Ben Bolker bbolker at gmail.com
Mon Jan 2 17:49:45 CET 2012


Jonas Stein <news <at> jonasstein.de> writes:

> 
> i have a list of values like this
> 
> x y
> 1 3
> 2 2

  [snip]

> 
> and need the inflexion points (and all max and min).
> Is there a nice way to get the local max, min and inflexion points?

  diff(y) gives you the first difference, the analogue of the gradient
  diff(diff(y)) gives the second difference, the analogue of the second
derivative.

  dy <- diff(y)
  d2y <- diff(dy)
  which(dy==0)  ## critical values
  sign(s2y)[which(dy==0)]  ## test for max/min/saddle
  which(d2y==0)   ## inflection points



More information about the R-help mailing list