Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close


Now we would like to calculate how long it takes our trucks and ships to complete their travels. To do this, we need two operations. First, we need to define the interval, or the amount of time between departure and arrival. We need to use the interval() function, which looks like this:

interval(start, end)

So we will write:

trucks$travel_interval <- interval(trucks$departure_datetime, trucks$arrival_datetime)

This is a necessary step. It will allow us to use another function to calculate the actual difference.


Using the interval() function and the ships data set, create intervals of date and time for the departure_datetime and arrival_datetime columns. Assign the result to the travel_interval column.

Observe that the interval contains two dates: the starting and ending ones.