0

I have a single excel file in a folder, and I want R to read any/all excel files in the directory.

When I tried the following:

excel_df <- read_excel("C:/Home/User/dbd/*.xlsx")

I get an error that the file path does not exist.

When I tried this:

base <- as.character("C:/Home/User/dbd/*.xlsx")

files <- file.info(list.files(path = base, pattern = '*.xlsx',
                              full.names = TRUE, no.. = TRUE))
daily_numebrs<-readxl::read_excel(rownames(files)[order(files$mtime)][nrow(files)])

as I proceed with other codes, it says the

Error in ...object 'daily_numbers' not found.
doubleD
  • 269
  • 1
  • 12
  • 1
    you need to loop over your list of filenames. check out https://stackoverflow.com/questions/32888757/how-can-i-read-multiple-excel-files-into-r – Ray May 14 '21 at 16:33

1 Answers1

0
library(readxl)
file.list <- list.files(pattern='*.xlsx')
df.list <- lapply(file.list, read_excel)

Source: How can I read multiple (excel) files into R?

tpetzoldt
  • 5,338
  • 2
  • 12
  • 29
Bart
  • 128
  • 8