MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Introduction to Importing Data in R

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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

# List the sheets in my_book
___

# Import the second sheet in my_book
___
Edit dan Jalankan Kode