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”
Exercise instructions
- Load the
readxl
package usinglibrary()
. It's already installed on DataCamp's servers. - Use
excel_sheets()
to print out the names of the sheets inurbanpop.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
___
This exercise is part of the course
Introduction to Importing Data in R
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 fileExercise 3: Import an Excel sheetExercise 4: Reading a workbookExercise 5: readxl (2)Exercise 6: The col_names argumentExercise 7: The skip argumentWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.