Skip to content
Prev 180830 / 398513 Next

Generic 'diff'

Wacek Kusnierczyk wrote:
[...]
[...]
btw., the error message here is confusing:

    lag = 1:2
    diff(1:10, lag=lag)
    # Error in diff.default(1:10, lag = lag) :
    #  'lag' and 'differences' must be integers >= 1

    is.integer(lag)
    # TRUE
    all(lag >= 1)
    # TRUE
  
what is meant is that lag and differences must be atomic 1-element
vectors of positive integers.  or rather integer-representing numerics:

    lag = 1
    diff(1:5, lag=1)
    # fine
    is.integer(lag)
    # FALSE

(the usual confusion between 'integer' as the underlying representation
and 'integer' as the represented number.)

vQ