Skip main navigation
We use cookies to give you a better experience, if that’s ok you can close this message and carry on browsing. For more info read our cookies policy.
We use cookies to give you a better experience. Carry on browsing if you're happy with this, or read our cookies policy for more information.

Skip to 0 minutes and 12 secondsHow about we use this new column that we made to go re-enforce one of the ideas we'd done earlier? Okay, let's go look at, for instance, the departure delays, and break them up a couple different ways. Okay, let's break them up according to the city of origin, and according to this new column we made called timeofday. And the function I wanna run on the data here is the length. I wanna find out how many flights there were broken up according to the origin and the time of day. And you get exactly that. Let's go look at the top of the matrix that was produced. Got the flights from the early evening, the early morning, late evening, and late morning there.

Skip to 1 minute and 2 secondsThere's the column headers, and there's the row headers. You've got the cities as well. For instance, you could go look at the flight tab of NDN, Cincinnati, and JFK. Specify those as the rows and leave the columns blank, so that you get all four of the columns.

Skip to 1 minute and 25 secondsThere you go.

Skip to 1 minute and 28 secondsWe can tabulate how many flights occur by splitting the flights according to both the city of origin and also the time of day when the flight departed.

Skip to 1 minute and 47 secondsWe get a matrix with all of the results. Let's go make sure it's actually a matrix, okay? We can go ask it for the class of that resulting object. It is indeed a matrix. Let's see what the dimension is. Should be about 300 something by 4, right, cuz there are about 303 cities. We have a matrix with 303 rows, 1 row per city, and 4 columns, 1 column per time of day.

Skip to 2 minutes and 21 secondsAnd then just like I showed you, we can restrict attention to the flights that departed from ND or Cincinnati or JFK.

Skip to 2 minutes and 35 secondsHere we did not specify the columns, so as a result, we get all four possible columns. Right here after this comma, where I'm sending it the two dimensions, the rows I want and then the columns I want, I haven't specified any columns. I've left this part blank in there. So that's why you get all four columns in the result.

Analyzing Flights by Time of Day for Departure and Origin Airport

Share this video:

This video is from the free online course:

Introduction to R for Data Science

Purdue University

Contact FutureLearn for Support