I have a data set that has information on where people went over a certain number of days period-- the data has three level of nesting in long format. First is person, second is day, third is location. Each row indicates a location. I have information type of location (home, work, etc), travel mode used to get to the location (walk, bike, public bus, etc.), and arrival and departure time. It is a daily travel journal that starts from home and ends at home.
I need to aggregate the data to create get information on the following types of journeys for each person for each day:
1. Journey from home to work without detour. (H-W)
2. Journey from home to work with detour. (H-dt-W) the number of detour does not matter.
3. Journey work to home without detour. (W-H)
4. Journey work to home with detour. (W-dt-H) the number of detour does not matter
5. Journey starting from home and ending at home and does not include work in between. (H-O..-H)
6. Journey starting from work and ending at work and does not include home in between. (W-O..-W)
For all these categories I need information of travel mode, and total travel time. For example: Imagine a Monday; a person wakes up at his home(H) has his breakfast and heads for office(W) on his car; on the way he stops at starbuck for a coffee (C) and then pick-ups a co-worker from their home(D). During the day at work, the person goes to visit a client at different location (E) and comes back to work; this time he takes train. The person then leave for home early that day because he needs to go for grocery. so the person return home, and goes for grocery at location(F), and comes back home, this time walked to the grocery store. This person made different kinds of journeys: 1)H-dt(C-D)-W, 2)W-O(E)-W, 3)W-H, 5)H-O(F)-H. He used different modes for the journey, 1) driving, 2)train, 3)walk. We can add travel time to each location as well using arrival and departure time. Below is the tabular form of the data. (The data below is only for a day for a person, but my data has more days and people).
###Data I have
Person Day ID Place Location_Code Mode Arrive Depart
5 1 0 H NA NA 8:00:00 AM
5 1 1 C D 8:30:00 AM 9:30:00 AM
5 1 2 D D 10:00:00 AM 11:00:00 AM
5 1 3 W D 11:30:00 AM 12:00:00 PM
5 1 4 E T 1:00:00 PM 1:30:00 PM
5 1 5 W T 2:30:00 PM 3:45:00 PM
5 1 6 H D 4:00:00 PM 4:30:00 PM
5 1 7 F P 5:00:00 PM 6:00:00 PM
5 1 8 H P 7:00:00 PM NA
###Data I want
Person Day Journey Type Mode/s Travel Time(hr)
5 1 H-dt-W DDD 1.5
5 1 W-O-W TT 2
5 1 W-H D 0.25
5 1 H-O-H PP 1.5
I have also enter image description hereattached a picture of the data as I have and the data I want to have.