determine over looping activity in a dataset in R

#1
I would greatly appreciate if someone help me out! I am not sure if we can do it in R!


I have 4 columns in my data set. first number of family, second number of persons in that family, col3 is the number of trips that a person make, col4 the place of the activity of that person and col5 start time of activity , col6 end of activity

Code:
            family    persons    trip      place   mode     loop   start time   end time

       1      1        1         home         -    1         3         8:45

       1      1        2          work       car     1       8:45        13:30

       1      1        3         shopping    walk    1       13:30       15

       1      1        4         home         car    1      15:00        15:30

       1      1        5         friends     walk    2      20:00        22:00

       1      1        6          home        walk   2      22:00       8:30

       1      2        1          home        -      1       3:00        8:00

       1      2        2           work        bus   1      8:00        17:00

       1      2        3           home        bus   1      17:00       3:00

       1      3        1          home       -       1       3:00       23:00

       1      3        2         friend       walk   1        23:00      24:00
each loop is a set of activities that start at home and finish at home. for the first person we have 2 loops :

first loop: home-> work -> shoping -> home
second loop: home -> friends -> home

for second person we have 1 loop

loop: home -> work -> home

I want to define an indicator to check that if car is available when a person wants to do an activity. the indicator is 1 if loops don't have intersection. So i want to check that if loops have intersection or not for a person who has car and other persons. for example in the above example the first person has a car in his first loop. So car is not available for others in the household from 8:45 to 15:30.
this loop has intersection with the loop of second person since he is working from 8 to 17.(so indicator is 1) but it does not have intersection with the third person since he goes from (23:00 to 24:00). you can ignore rows whose have - in their mode. I just put them to make it clear what is loop.

for second loop of the first person car is available because nobody else drive the car so indicator is 0.


So out put is some thing like this


Code:
  family persons  trip    place     mode  loop   start time     endtime    i

       1      1        1    home         -     1         3           8:45    -

       1      1        2    work       car     1       8:45        13:30     0

       1      1        3    shopping    walk    1       13:30       15       0

       1      1        4    home         bus    1      15:00        15:30    0

       1      1        5    friends     walk    2      20:00        22:00    0

       1      1        6    home        walk   2      22:00       8:30       0

       1      2        1    home        -      1       3:00        8:00      -

       1      2        2    work        bus   1      8:00        17:00       1

       1      2        3    home        bus   1      17:00       3:00        1

       1      3        1    home       -       1       3:00       23:00      -

       1      3        2    friend       walk   1        23:00      24:00    0
in other words indicator is 1 if car is not available for a loop, and 0 if it is available.