Psst! Check what courses we have in our offer, and get them all here to save \$727. Act fast–this deal is available only 3/14–3/21.
Introduction to data frames
Data frame structure
Accessing columns in a data frame
Accessing rows of a data frame
Accessing rows and columns combined in a data frame
Data frame analysis
Summary

Instruction

Awesome! Naturally, you can also extract more than one row from a data frame. To do so, you simply define multiple row positions inside the c() function, like this:

cities[c(1, 2, 3), ]

Just as with column indexing, if you try to extract a row using a position that goes beyond the number of rows of a data frame or that is less than 1, you will get an error. Keep in mind that row positions are numbered from 1 up to the total number of rows in a data frame.

For example, the cities data frame has 181 rows. The expression:

cities[182, ]
will give you an error.

Most of the time, you'll want to extract rows based on some condition (and not based on their positions). We'll cover that in the next exercise.

Exercise

Extract the three largest countries from the countries data frame. Don't forget to use the c() function inside the bracket operator, [...].

Stuck? Here's a hint!

Countries are stored in descending order of population size.