Dre Day
Dre Day

Reputation: 350

Reading in .xlsx

I have my working directory set and when I use this code for .xlsx:

files <- list.files(path = "foldername/", pattern = "*xlsx")
df <- read_excel(paste0("foldername/", files)
       

I receive an error that path must be a string. In other forms of writing the code I get path does not exist. When I run the same code for .xls it works fine. What could be happening? Thank you!

Upvotes: 1

Views: 162

Answers (1)

TarJae
TarJae

Reputation: 78917

Try this:

library(xlsx)

setwd("..../excel_files")

files = list.files(pattern = "*.xlsx")
df <- lapply(files, function(x) read.xlsx(x, sheetIndex = 1))

for (i in files) {
    df <- rbind(df, read.xlsx(i, sheetIndex = 1))
}

Upvotes: 1

Related Questions