Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction to data frames
Data frame structure
Accessing columns in a data frame
8. Accessing columns by name
Accessing rows and columns combined in a data frame
Data frame analysis
Summary

Instruction

Perfect! Moving on, let's now see how we can access a single column of a data frame object. The most convenient way to access the columns of a data frame is by their names.

We can retrieve a specific column by typing its name inside [...] like this:

cities["city"]

After we type the data frame name (cities), we write the column's name as a string. R will automatically display the column's values to the output console.

Don't forget to put the column name inside double or single quotes, as it must be passed in as a string.

Exercise

Display the column named region from the countries data frame.