R how can I calculate difference between rows in a data frame
dataframe, diff, r
Solution
diff wants a matrix or a vector rather than a data frame. Try
data.frame(diff(as.matrix(df)))
Problem
Here is a simple example of my 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 to binary operator ``` Can anyone tell me why this error occurs?