R using diff: non-numeric argument to binary operator error
I presume that in your tt[1,]
, that
class(tt[1,])
# [1] "data.frame"
So if you use as.numeric
, you should be okay. Try this:
diff(as.numeric(tt[1,]))
Here's an example that we can inspect:
tt <- data.frame(x = 1, y = 2)
is.vector(tt[1,])
# [1] FALSE
class(tt[1,])
# [1] "data.frame"
diff(tt[1,])
# Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] :
# non-numeric argument to binary operator
as.numeric(tt[1,])
# [1] 1 2
diff(as.numeric(tt[1,]))
# [1] 1