[R] Generic 'diff'

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue May 19 11:14:01 CEST 2009


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
>
>   

... and even non-integer-representing non-integers are fine:

    diff(1:5, lag=pi)
    # 3 3


vQ




More information about the R-help mailing list