I currently have a dataframe (df) that looks like:
> j
policyNumber driverName vehicleName
1 1 jason blue
2 1 josh red
3 1 jason green
4 2 jason orange
5 2 kyle orange
6 3 chris pink
7 3 ally purple
I would like to add distinct driver and vehicle ID's that depend on the policyNumber and driverName or vehicleName, respectively. My biggest issue is that I can not get a function that recognizes that the policy number has changed (so to reset the sequence to 1), and that the same entries may not be consecutive (like 'jason' in policyNumber 1).
I would like to have a dataframe that comes out to:
> j
policyNumber driverName vehicleName driverNumber vehicleNumber
1 1 jason blue 1 1
2 1 josh red 2 2
3 1 jason green 1 3
4 2 jason orange 1 1
5 2 kyle orange 2 1
6 3 chris pink 1 1
7 3 ally purple 2 2