How to estimate the time headway between two pair of vehicle arrival at a fixed point on road : [Speed and Headway data image file <---- click here so see the image file][1]


  [1]: https://i.stack.imgur.com/aQnVf.jpg

This is a very big headache doing this type of data manipulation in excel.

The challenge is I have to calculate the headway differences between pair of vehicles for different lanes.

Let me first describe the features of the data that is shown in the attached image link

v_type ----> is Vehicle type, 
where, 2w = two wheeler, car = standard car, auto = 3 wheeler vehicle, lcv = light commercial vehicle (smaller size good carrier)

lane ----> lane specify the road is a 3 lane decided road i.e. both side of the median the road comprises of three lanes and 1, 2, 3 is lane number on which the vehicle is moving

exit_time ----> exit time means the cumulative time in second one after another vehicle arrival at a particular section of a road. The image shows if first 2w cross the section or line after 4 second then the next auto cross after 9 second.
so the time headway of arrival of auto after 2w is 9-4 = 5 second. 

The challenge is here to segregate the data lane-wise say first I have to segregate the lane 1 vehicles and then I have to calculate time headway in different pair of vehicles like 

i) all 2w arrival after car pair, 
ii) car arrival after 2w, 
iii) 2w arrival after auto, 
iv) auto arrival after 2w,
v) lcv arrival after 2w, 
vi) 2w arrival after lcv

and after segregating all vehicles in par I have to calculate the headway differences between pairs by calculating the differences between vehicle pair arrival time

so the key challenges are

i) first segregate the vehicle pair of different types lane wise
ii) then calculate headway between them

This I have to do using R-programming. 

So any suggestion on codes will be appropriated.

   