Want to keep learning?

This content is taken from the Purdue University & The Center for Science of Information's online course, Introduction to R for Data Science. Join the course to learn more.

Skip to 0 minutes and 11 seconds So you’ll remember up above what we had done, as we’d gone and made a dot chart of all of the cities for which there were at least 4,000 flights from Indy. Like there were more than 10,000 flights to O’Hare and Atlanta from Indianapolis, and there were 8,000 to DTW and so on going downwards. There were about 4,000 flights at MDW. All of these are flights out of Indy. Can we store those into a vector V? So this was exactly that data that we’ve gone and plotted over here. But now what I could do is I could go and extract these airport names and get the information about what are those codes, okay, what cities and states did they correspond to?

Skip to 0 minutes and 52 seconds Okay, so let’s say remember that this is the data we plotted in the dot chart. That was what we ended up plotting. We still do not know where, city and state, these airports are located. Unless we just recognized the airport codes. And it might be nice to incorporate that into our plot, it’s the whole point here. So, as I told you for instance, I can go look up specific entries now in w, by putting in the airport code. One neat thing I might wanna put in there is names of this thing from up above. I might wanna go, use these airport codes as indices into w, okay?

Skip to 1 minute and 35 seconds So I’m gonna take the names of those guys and use them as indices into w. And those are exactly the right airport codes, the ones I want. The airport codes that show up over here, Atlanta and Charlotte and Denver and so on are exactly the ones that I want over here, okay? So what I’m gonna go do now is I’m gonna make another temporary vector, I’m gonna call it myvac. And it’s got exactly the stuff that I plotted. This is the data that we plotted earlier and I’m gonna go make the names of that vector that information from WB, exactly, those city and state and airport code names.

Skip to 2 minutes and 15 seconds Okay, so now if I go look at my vector, it’s no longer the same numbers that we had before with the airline codes, it’s now the actual information about the airport itself. And if I go make a dot chart now of this vector, instead of having just the airport codes here, it’s gonna have the actual airport names. Okay, now they’re not in sorted order, right, it’s got Tampa first. And it’s got Atlanta at the bottom and O’Hare somewhere in the middle. So we’ve still gotta put them in order. And there you go. Chicago is at the top, and then Atlanta, and all down to Midway just as we saw before.

Skip to 2 minutes and 50 seconds But we don’t just have the airline codes, we actually have the names and locations of those airports. So, if we didn’t know them before, we’ve now got that information. And it’s just another example of how powerful the indexing is in R. It takes some time. You have to try it on your own. I think it’s good to double check yourself to explain to other people what you’re doing, to have some conversation about it. Once you get used to the indexing in R, it’s so powerful and it just let’s you use R in a more flexible way.

Skip to 3 minutes and 18 seconds I encourage you to try it and I encourage you to utilize that to make plots that are a little more informative and insightful like the one we made here.

Revising Visualizations of Flight Paths

Consider the visualization we made, which shows 13 airports that served as destinations for at least 4,000 flights which originated in IND. Revise this visualization to show (only) the name of each such airport but not the city and state. Once you have done this, you may mark this step complete.

Share this video:

This video is from the free online course:

Introduction to R for Data Science

Purdue University