Introduction to data frames
Data frame structure
Accessing columns in a data frame
11. Accessing data frame columns with indexing
Accessing rows of a data frame
Accessing rows and columns combined in a data frame
Data frame analysis
Summary

Instruction

Good job! Another way to access a certain column of a data frame is by using an index. You can retrieve a specific column from a data frame by passing in that column's index as an argument to the bracket operator, [...]. Thus, cities[, 1] will retrieve the first column of a data frame, cities[, 2] will retrieve the second column, and so on. If you want to retrieve only city names for Versico's candidates, for example, you can do so like this (city is the second column in the citites data frame):

cities[, 2]

Notice that we need to put a coma before the column index inside the brackets. We'll explain why this comma is necessary later on.

Exercise

Which countries is Versico considering for its new offices? Display the names of these countries, given the countries data frame and the fact that the country name is the first column of this table.