-1
我有兩列我想以這種方式循環它應該計算(i)的到達 - (i + 1)的出發,並且值應該存儲在一個新列中。R編程循環差異
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
請幫忙完成上述數據的代碼。在RI嘗試,但也存在一些誤區
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
有在計算到達和離開的區別
我已經轉換由POSXClt
謝謝,我需要抵達ist值和離開第二個值之間的區別即(2012-01-26 08:50:00) - (2012-01-26 11:30:00)小時40分鐘 –