I have two variables and I would like to loop them such that, it should calculate arrival of(i) - departure of (i+1) and it should store the result in a new column
departure arrival
2012-01-26 08:15:00 2012-01-26 08:50:00
2012-01-26 11:30:00 2012-01-27 16:00:00
2012-01-27 18:00:00 2012-01-27 23:05:00
2012-02-11 00:20:00 2012-02-11 09:10:00
expected output
waiting time
(2012-01-26 08:50:00)-(2012-01-26 11:30:00) = 2 hr 40 min
(2012-01-27 16:00:00)-( 2012-01-27 18:00:00) = 2 hrs
(2012-01-27 23:05:00)- (2012-02-11 00:20:00)=14 days 13 hrs, 349 hrs
I tried this, but I kept getting errors:
for (i :length(data frame){
i <- i[17] #index of arrival column
j <- i+1[18] #index of departure column
diff = i-j
return diff
}
diff = waiting time