I have this data:
hhid perid actNo thisAct from to tripTime
8019450 1 1 home 180 1051 NA
8019450 1 2 school 1075 1245 24
8019450 1 3 socrec 1255 1260 10
8019450 1 4 home 1280 1619 20
Now, I want to insert three rows in which
thisAct=travel
from=(from-tripTime-1)
to=(from-1)
Then, the expected data look like this:
hhid perid actNo thisAct from to tripTime
8019450 1 1 home 180 1051 NA
*8019450 1 2 travel 1052 1074
8019450 1 3 school 1075 1245 24
*8019450 1 4 travel 1246 1254
8019450 1 5 socrec 1255 1260 10
*8019450 1 6 travel 1261 1279
8019450 1 7 home 1280 1619 20
Could you please how to insert those rows with asterisks?
Thank you.
Start by recreating your data:
Now calculate the travel times and put it in a data frame with the same shape as your data
then
rbindand sort: