Open In App

How to read multiple Excel files in R

In this article, we will discuss how to merge multiple Excel files in the R programming language.

Modules Used:

Functions Used:            

Syntax: list.files(path = “.”, pattern = NULL, all.files = FALSE,full.names = FALSE, recursive = FALSE, ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)



Syntax: lapply(X, FUN, …)

Syntax: bind_rows(…, .id = NULL)



Files in use:

gfg_data1.xlsx

gfg_data2.xlsx

gfg_data3.xlsx

Example: Merging Excel using R




library("dplyr")                                                
library("plyr")                                                 
library("readr")  
library("readxl")
  
gfg_data <- list.files(path = "Location/to/folder",    
                       pattern = "*.xlsx",
                       full.names = TRUE) %>% 
  lapply(read_excel) %>%                                           
  bind_rows                                                      
  
gfg_data                                                         

Output:

Article Tags :