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 main navigation

When Should You Fly?

When is the best time to fly? Dr. Ward explains.
11.7
As you think about having the ability to go and look at flights broken up in different kind of ways. You might wanna know which airline carriers are the best ones to travel on. We’ll again do something very general, just getting used to the T apply function. Let’s ask which airlines have the best average arrival delays, which have the worst average arrival delays. So again, the data that we wanna look at is arrival delay. We wanna break things up according to, well let’s go look in our list of variables here, we often have to go back our documentation with our variables here.
49
Yeah and variable number nine here, unique carrier, is gonna show what carrier code you have for each flight, okay, so we’ll go look at them, at the unique carrier code. That’s how we’ll break up our data, okay, we’ll look at the arrival delays broken up according to what’s the unique carrier. And again, just because it’s where we can use the T apply function, we’ll take the mean, and we use NA.RM is true. There’s only a few carriers there, okay, there’s just a few carriers. Delta for instance has carrier code DL and has a 7.8 minute arrival delay on average. American Airlines is code AA and has a 12.6 minute arrival delay on average.
91.3
There’s other kind of ways that we can use the T apply function. Maybe, for instance, we wanna know, in which month are there the most flights? There’s a couple different ways that we could do this, which month are there the most flights? Or in fact, I can just find all of the number of flights in all of the months. Okay, let’s try to do it that way, how many flights occur per month? One way we could do that, is we could just take a table of the month values, and see indeed, for each of the 12 months, that’s how many flights there are.
125.2
Another way we could do this, is we could look at the months, and break up that data according to the month. And what we’d want to do is with in each batch of data just find out how long it is, how many entries there are in there and to do that we can use the length function. We ought to get exactly the same result and we sure do. In general when you use the T apply function, if you wanna find out how many elements there are of a certain kind, you can use the T apply, take the data, and break it up according to itself.
153.8
And just see how many of each kind of the data there are in each group,. Or you can just use the table function and you’ll know how to get the same results either way.
This article is from the free online

Introduction to R for Data Science

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education