Skip to content
Prev 367022 / 398506 Next

diff doesnot work

diff() does not work on data.frames so you need to give it a column
from the data.frame, as a vector.
  diff(data.frame(P=c(1,2,3,5,7,11,13,17))$P)
  [1] 1 1 2 2 4 2 4

You get different errors for multi- and single-column data.frames
  > diff(data.frame(P=c(1,2,3,5,7,11,13,17), F=c(1,1,2,3,5,8,13,21)))
  Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] :
    non-numeric argument to binary operator
  > diff(data.frame(P=c(1,2,3,5,7,11,13,17)))
  data frame with 0 columns and 8 rows
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Mon, Feb 6, 2017 at 2:21 PM, george brida <george.brida at gmail.com> wrote: