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:
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.