I have a dataset:
client_id cohort year which_year frequency
7 2006 2011 6 10
7 2006 2012 7 11
7 2006 2013 8 17
17 2006 2011 6 9
17 2006 2012 7 4
17 2006 2013 8 7
19 2015 2015 1 2
19 2015 2016 2 20
19 2015 2017 3 30
I would like to create a variable "frequency_start" which takes the frequency at the minimum which_year for a client_id and replicates it among all rows where client_id = i. Like this:
client_id cohort year which_year frequency frequency_start
7 2006 2011 6 10 10
7 2006 2012 7 11 10
7 2006 2013 8 17 10
17 2006 2011 6 9 9
17 2006 2012 7 4 9
17 2006 2013 8 7 9
19 2015 2015 1 2 2
19 2015 2016 2 20 2
19 2015 2017 3 30 2
I've tried for loops with lapply and match with which.min but nothing worked properly. Do you have any idea what might help? I would be very, very grateful.