Lag                  package:Hmisc                  R Documentation

_L_a_g _a _N_u_m_e_r_i_c, _C_h_a_r_a_c_t_e_r, _o_r _F_a_c_t_o_r _V_e_c_t_o_r

_D_e_s_c_r_i_p_t_i_o_n:

     Shifts a vector 'shift' elements later.  Character or factor
     variables are padded with '""', numerics with 'NA'.

_U_s_a_g_e:

     Lag(x, shift = 1)

_A_r_g_u_m_e_n_t_s:

       x: a vector

   shift: positive integer specifying the number of observations to be
          shifted to the right

_D_e_t_a_i_l_s:

     A.ttributes of the original object are carried along to the new
     lagged one, but factor vectors are converted to character.

_V_a_l_u_e:

     a vector like 'x'

_A_u_t_h_o_r(_s):

     Frank Harrell

_S_e_e _A_l_s_o:

     'lag'

_E_x_a_m_p_l_e_s:

     Lag(1:5,2)
     Lag(letters[1:4],2)
     Lag(factor(letters[1:4]),2)
     # Find which observations are the first for a given subject
     id <- c('a','a','b','b','b','c')
     id != Lag(id)
     !duplicated(id)

