Importing Data from Excel in R

Microsoft Excel is another tool which is commonly used for data analysis. There are many R packages that can be used to interact with Excel. Once such package is readxl which was developed by Hadley Wickham.

An Excel file contains tabular data in multiple sheets. For this lesson, we have an excel sheet named stock-prices.xlsx (Downloadable above) that contains stock price data for December 2016 and November 2016 in two different sheets labeled - 'Dec-2016' and 'Nov-2016'.


It is generally a good idea to first explore your data by directly opening it in MS Excel before you import it in R. Now that we know what data we are importing, let's look at how we can import it using readxl.


We will use two functions from readxl package:

  • excel_sheets() is used to get a list of sheets in the excel file
  • read_excel() is used to actually import the data from an excel sheet

These functions support both .xls and .xlsx file formats.

Install and Load read.xl() Package

This content is for paid members only.

Join our membership for lifelong unlimited access to all our data science learning content and resources.

Lesson Resources

All Users