Open In App

How to Read xls files from R using gdata

Last Updated : 17 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Reading xls files from R using gdata is a useful way to import and manipulate data in R Programming Language. The gdata package provides a set of functions for reading and writing data in various file formats, including xls files. In this article, we will discuss the concepts related to reading xls files in R using gdata, the steps needed to do so, and provide some examples to help you get started.

The gdata package is a powerful tool for working with various file formats in R. It provides a set of functions for reading and writing data in various file formats, including xls files. The package also provides some useful functions for manipulating and cleaning data, which can be very helpful when working with large or complex data sets.

Steps to read xls files using gdata:

              The steps needed to read xls files in R using gdata are relatively simple. First, you will need to install and load the gdata package. This can be done using the following command:

install.packages("gdata")
library(gdata)

Once the package is loaded, you can use the read.xls() function to read an xls file into R. The gdata package uses Perl scripts to convert XLS files to CSV files and then read the CSV files into R, if Perl is not installed on your system, you can install Perl on your system.

Syntax : read.xls(file, sheet = 1, verbose = FALSE)

Where,

  • file: This parameter is required and specifies the path to the xls file that you want to read. It can be a string, a URL, or a connection.
  • sheet: This parameter is optional and specifies the sheet number or name that you want to read. By default, it is set to 1, which means the function will read the first sheet in the file.
  • verbose: This parameter is optional and specifies whether or not to display detailed information about the process of reading the file. By default, it is set to FALSE, which means the function will not display any additional information.
  • perl: name of the perl executable to be called.

Example:

 

Here are some examples of how to use the read.xls() function to read different types of xls files in R using gdata.

Example 1: Reading a simple xls file

R




data <- read.xls("S:\\file.xls")
View(data)


Output:

                   Name Quantity                          Component
1                    U3        1                     Arduino Uno R3
2 DISTUltrasonic Sensor        1         Ultrasonic Distance Sensor
3                    U1        1 PCF8574-based, 32 LCD 16 x 2 (I2C)

Example 2: Reading a specific sheet in an xls file

R




library(gdata)
data <- read.xls("S:\\file.xls", sheet = 2)
View(data)


Output:

  NO   Name
1  1 Satyam
2  2  Suraj
3  3  Pawan


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads