CommencerCommencer gratuitement

List and read Excel sheets

Just as readxl and gdata, you can use XLConnect to import data from Excel file into R.

To list the sheets in an Excel file, use getSheets(). To actually import data from a sheet, you can use readWorksheet(). Both functions require an XLConnect workbook object as the first argument. When using the readWorksheet() function, the sheet argument can accept either the name of the sheet (as a string) or the sheet's position number (as an integer) within the workbook.

You'll again be working with urbanpop.xlsx (view). The my_book object that links to this Excel file has already been created.

Cet exercice fait partie du cours

Introduction to Importing Data in R

Afficher le cours

Instructions

  • Print out the sheets of the Excel file that my_book links to.
  • Import the second sheet in my_book as a data frame. Print it out.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Build connection to urbanpop.xlsx
my_book <- loadWorkbook("urbanpop.xlsx")

# List the sheets in my_book
___

# Import the second sheet in my_book
___
Modifier et exécuter le code