diff - R how can I calculate difference between rows in a data frame -


here simple example of problem:

> df <- data.frame(id=1:10,score=4*10:1) > df        id score     1   1    40     2   2    36     3   3    32     4   4    28     5   5    24     6   6    20     7   7    16     8   8    12     9   9     8     10 10     4     > diff(df)  error in r[i1] - r[-length(r):-(length(r) - lag + 1l)] :    non-numeric argument binary operator 

can tell me why error occurs?

diff wants matrix or vector rather data frame. try

data.frame(diff(as.matrix(df))) 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

Php - Delimiter must not be alphanumeric or backslash -

Delphi interface implements -