diff                  package:base                  R Documentation

_L_a_g_g_e_d _D_i_f_f_e_r_e_n_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Returns suitably lagged and iterated differences.

_U_s_a_g_e:

     diff(x, ...)

     ## Default S3 method:
     diff(x, lag = 1, differences = 1, ...)

     ## S3 method for class 'POSIXt':
     diff(x, lag = 1, differences = 1, ...)

_A_r_g_u_m_e_n_t_s:

       x: a numeric vector or matrix containing the values to be
          differenced.

     lag: an integer indicating which lag to use.

differences: an integer indicating the order of the difference.

     ...: further arguments to be passed to or from methods.

_D_e_t_a_i_l_s:

     'diff' is a generic function with a default method and ones for
     classes '"ts"' and '"POSIXt"'. 'NA''s propagate.

_V_a_l_u_e:

     If 'x' is a vector of length 'n' and 'differences=1', then the
     computed result is equal to the successive differences
     'x[(1+lag):n] - x[1:(n-lag)]'.

     If 'difference' is larger than one this algorithm is applied
     recursively to 'x'. Note that the returned value is a vector which
     is shorter than 'x'.

     If 'x' is a matrix then the difference operations are carried out
     on each column separately.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'diff.ts', 'diffinv'.

_E_x_a_m_p_l_e_s:

     diff(1:10, 2)
     diff(1:10, 2, 2)
     x <- cumsum(cumsum(1:10))
     diff(x, lag = 2)
     diff(x, differences = 2)

     diff(.leap.seconds)

