I have a dataframe with two columns departuretime and arrivaltime. I want to compare the arrivatime with the departuretime and in case the arrivaltime is greater than the departuretime, add 1 to it.
departuretime arrivaltime
<S3: POSIXct> <S3: POSIXct>
2019-03-04 23:32:00 2019-03-04 03:55:00
2019-03-05 01:38:00 2019-03-04 05:27:00
2019-03-04 22:59:00 2019-03-04 06:45:00
2019-03-04 22:40:00 2019-03-04 00:01:00
2019-03-04 22:13:00 2019-03-04 00:08:00
2019-03-04 22:38:00 2019-03-04 00:08:00
2019-03-05 00:36:00 2019-03-04 04:19:00
2019-03-04 22:12:00 2019-03-04 00:19:00
2019-03-04 23:19:00 2019-03-04 02:13:00
2019-03-04 21:27:00 2019-03-04 00:21:00
I have tried the below code
mutate(if(departuretime > arrivaltime) {
arrivaltime = ymd_hms(arrivaltime) + days(1)
})
But this doesn't seem to make any difference. I'm not sure why.