Open In App

How to import an Excel File into R ?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

In this article, we will discuss how to import an excel file in the R Programming Language. There two different types of approaches to import the excel file into the R programming language and those are discussed properly below.

File in use:

Method 1: Using read_excel()

In this approach to import the Excel file in the R, the user needs to call the read_excel() function from readxl library of the R language with the name of the file as the parameter. readxl() package can import both .xlsx and .xls files. This package is pre-installed in R-Studio. With the use of this function, the user will be able to import the Excel file in R.

Syntax: read_excel(filename, sheet, dtype = “float32”)

Parameters:

  • filename:-File name to read from.
  • sheet:-Name of the sheet in Excel file.
  • dtype:-Numpy data type.

Returns:

The variable is treated to be a data frame.

Example:

R




library(readxl)
 
gfg_data=read_excel('Data_gfg.xlsx')
 
gfg_data


Output:

Method 2: Using inbuilt menu Options of Rstudio

This approach is the easy approach to import the excel file in R compared with the previous one as this is the only approach to import an excel file in R where the user need not type any code in the console to import the excel file. Further, here user just needs to work on the environment window of the studio.

Environment window of the Rstudio:

Steps to import excel file using Dataset option from the environment window of Rstudio:

Step 1: Select the Import Dataset option in the environment window. Here the user needs to select the option to import the dataset from the environment window in Rstudio.

Step 2: Select the option of “From excel” under the import Dataset option. In this step, the user needs to select the option to “from excel” as the file is in the form of excel under the import dataset option to import the excel file.

Step 3: Select the browse option and select the excel file to be imported. Now, under this with the click to the browse option user will be given the choice to select the needed excel file to be imported in R.And then the user need to select the needed excel file to be imported in R.

Step 4: Select the import option and the excel file is successfully imported. Now, in this final step user need to select the import button and this will lead to successful importation of the selected excel file by the user in R.

The user chose the dataset according to their choice means that changing the name of the file and type of sheet. May be there are 2 sheets , he choose 2nd one then he choose the 2nd list with the help of sheet option and in max rows how much rows he wants from the data he put into it. And in  skip box , he skips the rows how much he want. In NA box, he write some value in it , if this value is in the data then it makes as NA.

There is also another method for to import the excel files into R-Studio.
Step 1: Click on file
Step 2: In file, click import dataset then choose from excel.


Last Updated : 22 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads