How to Read xls files from R using gdata
Last Updated :
28 Apr, 2025
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
Similar Reads
How to Read Zip Files into R In the R Programming Language Zip files are compressed archives that store one or more files or directories in compressed format. They are commonly used to package and distribute files, particularly when working with huge datasets or many files. Zip files not only conserve disc space but also facili
4 min read
How to Read XML File in R? XML (Extensible Markup Language) can be a widely used format for storing and transporting data. It can be structured and allowing the both humans and machines to easily parse and interpret the data it contains. In R programming, reading and processing XML files is straightforward thanks to the vario
5 min read
How to Read a CSV from URL into R? In this article, we are going to see how to read CSV files from URL using R Programming Language. Method 1: Using Base RÂ Here we are using read.csv() methods, which is an inbuilt function in R programming. This function is similar to Python because it read the CSV file and returns the data into dat
1 min read
Read Data Using XLSX Package in R R is a powerful programming language used for data analysis and manipulation. The XLSX package in R is an excellent tool for reading and writing Excel files. This package allows R users to work with data stored in Excel spreadsheets directly in their R environment. In this article, we will walk you
3 min read
How to read JSON files in R JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy to read for humans as well as machines to parse and generate. It's widely used for APIs, web services and data storage. A JSON structure looks like this:{ "name": "John", "age": 30, "city": "New York"}JSON data c
2 min read
How to plot a graph in R using CSV file ? To plot a graph in R using a CSV file, we need a CSV file with two-column, the values in the first column will be considered as the points at the x-axis and the values in the second column will be considered as the points at the y-axis. In this article, we will be looking at the way to plot a graph
2 min read