How to merge multiple excel files with multiple worksheets in R with different number of rows and columns in R

Hi guys,

I am relatively new to R. I am not sure about how to merge multiple files with multiple worksheets with different numbers of rows and columns into one table. Is it possible? Do I use full join or rbind? I managed to import the files and worksheets in R but I don't know how to merge all these files in one table

File A -worksheet 1
File B - worksheets 1-74
File C- worksheets 1-9

I used the code below to import the files and worksheets.

library(tidyverse)
library(readxl)

read_excel_allsheets <- function(filename){
sheets <- readxl::excel_sheets(filename)
x <- lapply(sheets, function(x) readxl::read_excel(filename, sheet = x))
names(x) <- sheets
x
}
files <- list.files(path = "Data/Multiple files/", pattern = "*.xlsx", full.names = TRUE)
out <- lapply(files, read_excel_allsheets)
names(out) <- basename(files)

Now how do I merge these files and worksheets together.

How are the sheets related to each other? Do they have a unique identifier or identifiers?

The key thing, as asked by StatSteph, is how they relate.
Do you need to add some (SQL UNION) using rbind or do lookups (SQL JOIN) using inner_join/left_join (or merge)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.