Valeria Arango
Valeria Arango

Reputation: 327

How to create a dataframe in R from an Excel with several sheets?

I have an Excel workbook with 10 sheets, each one with the name of a country. The first row of all sheets is the same. What I need is to join them all in a single dataframe in R. I have been using the "readxlsx" library, but I can only read one sheet at a time, and I still don't know how to join them all ...

Any help will be very appreciated.

Upvotes: 1

Views: 433

Answers (1)

Koundy
Koundy

Reputation: 5503

Try this. read all the files into a list using for loop and then you can combine all the data frames

data_list <- list()

for(i in 1:10){
data_list[[i]] <- readxlsx('excel_file', sheet = i)
}

combined_dataframe <- do.call(rbind, data_list)

Upvotes: 1

Related Questions