Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
Introduction to data frames
Data frame structure
3. Displaying the first six rows of a data frame - head()
Accessing columns in a data frame
Accessing rows and columns combined in a data frame
Data frame analysis
Summary

Instruction

Correct! Most of the time, you'll work with large data sets. Displaying a whole data frame to the output console can be inefficient. In that case, it will be very useful to display only the first several rows to the output console. You can do that with head() function. Here's an example:

head(cities)

When you call this function, R will display only the first six cities (rows) of the data frame named cities.

If you want to display more than six rows, you can use a call to head() with a second optional argument that specifies the number of rows you wish to retrieve:

head(cities, 10)

Exercise

Versico's management definitely wants to include cities from the most populated countries in its expansion plan. The company is analyzing country population data that are stored in a data frame called countries. In the countries data frame, countries are once again stored in descending order of population. This means that the first six countries in the data frame have the largest populations in Europe.

Display the first six countries of the countries data frame.