How to create lag variables

In base R the function lag() is useful for time series objects. Here you have a dataframe and the situation is somewhat different. You could try the following, which I admit is not very elegant: An alternative consists in using the Lag() function (with capital “L”) from the Hmiscpackage:

Categories r Tags ,