Get Started

List the sheets of an Excel file

Before you can start importing from Excel, you should find out which sheets are available in the workbook. You can use the excel_sheets() function for this.

You will find the Excel file urbanpop.xlsx (view) in your working directory (type dir() to see it). This dataset contains urban population metrics for practically all countries in the world throughout time (Source: Gapminder). It contains three sheets for three different time periods. In each sheet, the first row contains the column names.

This is a part of the course

“Introduction to Importing Data in R”

View Course

Exercise instructions

  • Load the readxl package using library(). It's already installed on DataCamp's servers.
  • Use excel_sheets() to print out the names of the sheets in urbanpop.xlsx.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Load the readxl package
library(___)

# Print the names of all worksheets
___
Edit and Run Code

This exercise is part of the course

Introduction to Importing Data in R

BeginnerSkill Level
4.2+
26 reviews

In this course, you will learn to read CSV, XLS, and text files in R using tools like readxl and data.table.

Excel is a widely used data analysis tool. If you prefer to do your analyses in R, though, you'll need an understanding of how to import .csv data into R. This chapter will show you how to use readxl to do so.

Exercise 1: readxl (1)Exercise 2: List the sheets of an Excel file
Exercise 3: Import an Excel sheetExercise 4: Reading a workbookExercise 5: readxl (2)Exercise 6: The col_names argumentExercise 7: The skip argument

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free