Skip to 0 minutes and 12 seconds 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.
Skip to 0 minutes and 49 seconds 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.
Skip to 1 minute and 31 seconds 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.
Skip to 2 minutes and 5 seconds 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.
Skip to 2 minutes and 34 seconds 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.