How to import an Excel File into R ? - GeeksforGeeks (2024)

Last Updated : 22 Feb, 2023

Improve

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:

How to import an Excel File into R ? - GeeksforGeeks (1)

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:

Output:

How to import an Excel File into R ? - GeeksforGeeks (2)

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:

How to import an Excel File into R ? - GeeksforGeeks (3)

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.

How to import an Excel File into R ? - GeeksforGeeks (4)

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.

How to import an Excel File into R ? - GeeksforGeeks (5)

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.

How to import an Excel File into R ? - GeeksforGeeks (6)

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.

How to import an Excel File into R ? - GeeksforGeeks (7)


Like Article

Suggest improvement

Share your thoughts in the comments

Please Login to comment...

How to import an Excel File into R ? - GeeksforGeeks (2024)
Top Articles
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 6336

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.