0

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)
2
  • try df <- read_excel( path ) Commented Mar 7, 2019 at 20:58
  • Are you trying to read multiple files into R or just a single one? From the last line in your code it is a bit unclear which? Commented Mar 7, 2019 at 21:18

1 Answer 1

2

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!

Sign up to request clarification or add additional context in comments.

1 Comment

This works great for loading multiple sheets but is there an easy way to add the sheet name to the dataframe?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.