Paula
Paula

Reputation: 703

Reading and loading multiple Excel sheets in R

I want to read and load an Excel file into my environment, I'm just getting a list.

path <- "data/data.xlsx"

path %>% 
  excel_sheets() %>% 
  set_names() %>% 
  map(read_excel, path = path)

Upvotes: 0

Views: 363

Answers (1)

Raul Guerrero
Raul Guerrero

Reputation: 408

You could try: For this example i made a xlsx with 3 sheets.

library(readxl)
# Get the sheets count
sheets <- excel_sheets("some.xlsx")

for (i in 1 : length(sheets)) {

 shts <- paste("x", i, sep = ".")
 # Read every single sheet and assign to variable x1, x2, x3 etc...
 assign(shts, read_excel("c:/Temporal/TEST.xlsx", sheet=sheets[i]))
}

Result:

enter image description here

I hope this helps!

Upvotes: 2

Related Questions