How to read Excel file and select specific rows and columns in R? Last Updated : 20 May, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to read an Excel file and select specific rows and columns from it using R Programming Language. File Used: To read an Excel file into R we have to pass its path as an argument to read_excel() function readxl library. Syntax: read_excel(path) To select a specific column we can use indexing. Syntax: df [ row_index , column_index ] Here df represents data frame name or Excel file name or anything Extracting specific rows from Excel file For this, we have to pass the index of the row to be extracted as input to the indexing. As a result, the row at the provided index will be fetched and displayed. Example 1 : R library(readxl) setwd('C:/Users/KRISHNA KARTHIKEYA/Documents') df=read_excel('OSWT1.xlsx') a=df[5,] print(a) Output : Example 2 : R library(readxl) setwd('C:/Users/KRISHNA KARTHIKEYA/Documents') df=read_excel('OSWT1.xlsx') a=df[6,] print(a) Output : Example 3 : R library(readxl) setwd('C:/Users/KRISHNA KARTHIKEYA/Documents') df=read_excel('OSWT1.xlsx') a=df[7,] print(a) Output : To get multiple rows similarly not much modification is required. The index of the rows to be extracted should be passed as a vector to the row_index part of indexing syntax. Example 4 : R library("readxl") df=read_excel("C:/users/KRISHNA KARTHIKEYA/Documents/OSWT1.xlsx") print(df[c(2,3),]) Output : Extracting specific columns from Excel file This is similar to the approach followed above except that to extract the column index of the column needs to be given as an argument. Example 1 : R library(readxl) setwd('C:/Users/KRISHNA KARTHIKEYA/Documents') df=read_excel('OSWT1.xlsx') a=df[,2] print(a) Output : Example 2: R library(readxl) setwd('C:/Users/KRISHNA KARTHIKEYA/Documents') df=read_excel('OSWT1.xlsx') a=df[,3] print(a) Output : Example 3 : R library(readxl) setwd('C:/Users/KRISHNA KARTHIKEYA/Documents') df=read_excel('OSWT1.xlsx') a=df[,4] print(a) Output : To get multiple columns at once the index of the columns to be extracted should be given as a vector in column_index part of the indexing syntax. All the columns with the index provided will be fetched and displayed. Example 4 : R library("readxl") df=read_excel("C:/users/KRISHNA KARTHIKEYA/Documents/OSWT1.xlsx") print(df[,c(2,3)]) Output : Comment More infoAdvertise with us Next Article How to read excel file in R ? K krishnakarthikeyakhandrika Follow Improve Article Tags : R Language R-Excel Similar Reads Read CSV file and select specific rows and columns in R In this article, we are going to see how to read CSV file and select specific rows and columns in R Programming Language. CSV file: To import a CSV file into the R environment we need to use a pre-defined function called read.csv(). Pass filename.csv as a parameter within quotations. First, we need 1 min read Choose Specific Columns of a Data Frame in R Programming - select() Function select() function in R Language is used to choose whether a column of the data frame is selected or not. Syntax: select(x, expr) Parameters: x: Data frame expr: condition for selection Example 1: Python3 1== # R program to select specific columns # Loading library library(dplyr) # Create a data fram 2 min read How to read excel file in R ? We may work with structured data from spreadsheets, take advantage of R's capabilities for data analysis and manipulation, and incorporate Excel data into other R processes and packages by reading Excel files in R. The readxl package offers a simple and effective method for reading Excel files into 3 min read Specify Row Names when Reading Excel File in R In this article, we are going to specify the row names when reading Excel file in the R Programming language. Specifying row names when reading a file using row.names argument of the read.xlsx2() function. This is the easiest approach to specify the row names when reading a file in the R programming 2 min read How to Convert a CSV File to Microsoft Excel in R CSV refers to Comma-Separated Values. It holds plain text as a series of values (cells) separated by commas (, ) in a series of lines (rows). CSV file can actually open in a text editor and read it. On the other hand, Excel is used to display the data in horizontal and vertical rows. The data are u 2 min read How to write in a specific Row or column Using write.xlsx in R The Excel File contains cells where the data can be stored in them. To deal with Excel Files in R programming Language we have a package named xlsx. Using the write.xlsx() function present in that package we are going to insert data into an excel file. We are going to insert data at a specified row 2 min read Like