Import multiple excel sheets into in R
In this article, we are going to see how to import multiple Excel sheets into the R language.
Excel provides us with multiple worksheets. For example, in the below Excel workbook StudentData, we have two worksheets – sheet 1 is Student Details and sheet 2 is Subject Details.
For importing multiple Excel sheets into R, we have to, first install a package in R which is known as readxl. After successfully installing the package, we have to load the package using the library function is R.
install.packages('readxl')
Once we have completely installed and loaded the package in RStudio, the next job is to import the excel workbook and check the number of sheet it contains. We can do this using the excel_sheets function.
R
library ( "read_excel" )
excel_sheets ( "StudentData.xlsx" )
|
Output:
'StudentDetails' 'SubjectDetails'
We have an Excel file named as “StudentData” and we have already saved it in our working directory. It contains two sheets named StudentDetails and SubjectDetails. We have a function in R called read_excel() which we will use to import specific sheet into R. If no argument is specified, then the read_excel() will by default import the first Excel sheet.
Syntax: read_excel(arg)
Code:
R
StudentDet<- read_excel ( "StudentData.xlsx" ,
sheet = 1)
StudentDet<- read_excel ( "StudentData.xlsx" ,
sheet = "StudentDetails" )
SubjectDet<- read_excel ( "StudentData.xlsx" ,
sheet = "SubjectDetails" )
head (StudentDet)
head (SubjectDet)
|
Output:
Last Updated :
17 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...