Create lead and lag variables in R
问题 I have to create lead and lag variables like below in R Suppose i have a dataframe which has details about a customer's visit to any store... CustomerID Dateofvisit 1 1/2/2013 1 1/3/2013 1 1/7/2013 2 1/9/2013 2 1/14/2013 2 2/14/2013 3 1/4/2013 3 1/5/2013 As we can see, there are 3 customers with different visit dates.. When i apply a lag function on the above...(i created my own function,)..it becomes like below: CustomerID Dateofvisit Laggeddate 1 1/2/2013 - 1 1/3/2013 1/2/2013 1 1/7/2013 1