The readxl R package makes it very easy and straightforward to read data from Excel files into R:
We start by loading the module into R:
library(readxl)
Reading Excel data with readxl is simple; we just need to call the read_excel function and pass in the file path, as follows:
read_excel("data.xls")
readxl supports both the old XLS and the new XLSX format. It guesses the format from the extension of the file being read:
read_excel("data.xlsx")
Excel files sometimes have multiple sheets. For example, the following Excel file has multiple sheets:
You can easily handle them with the readxl package. To see the number of sheets in the Excel document, use the excel_sheets command:
excel_sheets("data.xlsx")
#1> [i] "sheet1" "sheet2"
We can also specify which sheet should be accessed...