Line 80: tdiff1 <- tr1$time[i] - tr2$time[iv] needs to be replaced by
tdiff1 <- difftime(tr1$time[i],tr2$time[iv])
Line 81: tdiff2 <- tr2$time[iv+1] - tr2$time[iv] needs to be replaced by
tdiff2 <- difftime(tr2$time[iv+1],tr2$time[iv],units = units(tdiff1))
In the current code, tdiff1 and tdiff2 may be found by two different units e.g. secs or mins and as a result "ratio" will get a wrong value and it affects final result.
Line 80: tdiff1 <- tr1$time[i] - tr2$time[iv] needs to be replaced by tdiff1 <- difftime(tr1$time[i],tr2$time[iv])
Line 81: tdiff2 <- tr2$time[iv+1] - tr2$time[iv] needs to be replaced by tdiff2 <- difftime(tr2$time[iv+1],tr2$time[iv],units = units(tdiff1))
In the current code, tdiff1 and tdiff2 may be found by two different units e.g. secs or mins and as a result "ratio" will get a wrong value and it affects final result.