I've a data table where in I'm trying to get where is it causing a delay using the time stamps I've. I've a tracking number which is going from point A to point B
`df
ID t1 t2 t3 t4
ABC 2017-07-05 12:30 2017-07-05 13:32 2017-07-05 14:00 2017-07-05 11:15
ABC 2017-07-05 14:30 2017-07-05 15:11 2017-07-05 16:00 - `
where
t1= Planned Arrival time
t2= Actualt arrival time
t3= plannedeparturetime
t4= Actualdeparturetime
The first row shows date and time at point A and the second shows it at point B.
what I need to do is to find where the delay occured so I did some calculations
i <- strptime(x = as.character(df$t1),format = "%Y-%m-%d %H:%M") i1 <- strptime(x = as.character(df$t2),format = "%Y-%m-%d %H:%M") df$r1<-difftime(h, h1, units ="min")
so that is giving me the time difference between t1 and t2 and similarly for t3 and t4 and I get
f1- f2 118 -165 -139
then I tried to give a condition df$d2=ifelse(30>c,"delay bypersonc","ontime")
which gave me another column with
`d2
delay bypersonc
delay bypersonc`
Now i've to do two things 1. to find who is causing the delay personc (who is like the driver) or person D ( is customer who has to get the items) where the load has to first go to person D on time and get of out on time which are (planned arrival and departure time) so that he can reach to point B on the time(planned arrival time present in second row)
let suppose in this the driver was to arrive at 12:30 but he came at 10:30 (so he is early here) and is supposed to leave from here at 14:00 but leaves at 11:15 (he left early here as well) and he was planned to come at 14:30 at point B (second row data) but comes at 15:11 which is late
so at point B he is late and overall the delay was caused by driver or personc so I want this to be the output.
this leads to four cases
`c comes on time at A and leaves on time at A ---- no delay`
`c comes late at A but leaves early at point A --- delay by c`
` c comes late and leave late at A ---- delay by c`
`c comes early but leaves late from A ----- delay by customer at A`
so I want this conditions to be fullfilled. I wrote some if statements which were very dirty. Any suggestion would help
Aucun commentaire:
Enregistrer un commentaire