Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to Importing Data in R

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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

# List the sheets in my_book
___

# Import the second sheet in my_book
___
Code bewerken en uitvoeren