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 13 seconds Let’s continue with that example. What I’m gonna look at now, is the total number of flights month by month, just from Indy. Here are all the flights, month by month, from Indianapolis Airport.

Skip to 0 minutes and 26 seconds And to do that, I could put in a 1:12.

Skip to 0 minutes and 32 seconds Or another way of doing that is don’t put anything for the columns. You still gotta put a comma before how many columns, but if you don’t tell it which ones, it’ll assume you want all of them. Okay, same effect, just leave the column specification blank, but make sure to put a comma between the rows and the columns. That’s one of the biggest mistakes I see students, and even myself do. Is just forgetting to put that comma there between which rows I want and which columns I want. If you’re gonna leave the columns blank you’ve still got to put a comma. You don’t put a comma, it’s going to think you just want to specify in one dimension.

Skip to 1 minute and 11 seconds But you’ve got to tell which rows and which columns or leave one or the other blank.

Skip to 1 minute and 17 seconds What about Chicago?

Skip to 1 minute and 21 seconds If you want Chicago O’Hare, could do this, right? Just change the IND to ORD. And now what about both?

Skip to 1 minute and 35 seconds If you want them both at once in here.

Skip to 1 minute and 39 seconds I can go put IND and ORD. You see I’m gonna get a matrix back.

Skip to 1 minute and 51 seconds We can check that the result is a matrix. I think I told you that all the time I’m putting a class around the things that I wanna check.

Skip to 2 minutes and 0 seconds I’ll truncate that line so you can see it a little more easily. But it should tell me that I got a matrix back. Indeed, I did.

Skip to 2 minutes and 9 seconds How big is the matrix? It should be 2 by 12. Let’s check. Instead of class, we just ask it for the dimension. You notice I highlight both the rows when I wanna run my command there, indeed, it’s a 2 by 12.

Leaving a Specification Blank

Can you create a table with 3 rows and 12 columns, showing the monthly counts for flights departing from ATL, ORD, and DFW?

Comment below.

Share this video:

This video is from the free online course:

Introduction to R for Data Science

Purdue University