I have a data that determines the package of each customer at a point in time.
date    customer    package
1/1/2015    12        2
2/1/2015    12        5
3/1/2015    12        2
4/1/2015    12        3
5/1/2015    12        6
6/1/2015    12        7
7/1/2015    12        5
8/1/2015    12        3
9/1/2015    12        2
I want to group by customer and get the largest package he has reached to before that point in time. The output should be like that:
date    customer    package lagged_max
1/1/2015    12        2        2
2/1/2015    12        5        5
3/1/2015    12        2        5
4/1/2015    12        3        5
5/1/2015    12        6        6
6/1/2015    12        7        7
7/1/2015    12        5        7
8/1/2015    12        3        7 
9/1/2015    12        2        7
data %>% group_by(customer) %>% mutate(max_package = max(package)
Gets the maximum package overall but I want it to ignore only that in the past.
 
    