Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
Introduction to data frames
Data frame structure
Accessing columns in a data frame
10. Accessing multiple columns of a data frame by name
Accessing rows and columns combined in a data frame
Data frame analysis


You can also access multiple columns of a data frame. You do so by first typing the data frame name followed by the bracket operator, [...], in which you pass a vector with the names of all columns you wish to display. For example, if you want to retrieve the columns named city and population from the cities data frame, you can type the following:

cities[c("city", "population")]

Notice that the column names are surrounded by double quotes. However, it is perfectly possible to use single quotes.


Extract the columns country and population from the countries data frame.