I have a problem similar to this question R how can I calculate difference between rows in a data frame; I try to apply this solution https://stackoverflow.com/a/16212173/15485 with this code
df <- data.frame(timestamp=c("2015-02-02 09:53:44","2015-02-02 09:54:53","2015-02-02 09:55:52"),cnt=c(1,2,3))
df$timestamp <- strptime( df$timestamp, "%Y-%m-%d %H:%M:%S")
apply( df , 2 , diff )
but I get this error:
Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] :
non-numeric argument to binary operator
If I remove the column timestamp
(which is of type POSIXlt
) then it will work fine.
But... diff(df$timestamp)
is working well:
Time differences in secs
[1] 69 59
So, what am I missing?