Get Started

The skip argument

Another argument that can be very useful when reading in Excel files that are less tidy, is skip. With skip, you can tell R to ignore a specified number of rows inside the Excel sheets you're trying to pull data from. Have a look at this example:

read_excel("data.xlsx", skip = 15)

In this case, the first 15 rows in the first sheet of "data.xlsx" are ignored.

If the first row of this sheet contained the column names, this information will also be ignored by readxl. Make sure to set col_names to FALSE or manually specify column names in this case!

The file urbanpop.xlsx (view) is available in your directory; it has column names in the first rows.

This is a part of the course

“Introduction to Importing Data in R”

View Course

Exercise instructions

  • Import the second sheet of "urbanpop.xlsx", but skip the first 21 rows. Make sure to set col_names = FALSE. Store the resulting data frame in a variable urbanpop_sel.
  • Select the first observation from urbanpop_sel and print it out.

Hands-on interactive exercise

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

# Import the second sheet of urbanpop.xlsx, skipping the first 21 rows: urbanpop_sel
urbanpop_sel <- read_excel("urbanpop.xlsx", sheet = ___, col_names =___, skip = ___)

# Print out the first observation from urbanpop_sel
___

This exercise is part of the course

Introduction to Importing Data in R

BeginnerSkill Level
4.2+
25 reviews

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

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