I have a directory of 332 Excel files which I'm reading into R as follows:
list_files <- list.files(path = "C:/Users/mslomka/Documents/R/Datasets/Week 2", pattern = ".csv")
read_files <- lapply(list_files, read.csv)
However, when I subset the read_files
list, all the components are lists rather than data frames/matrices (which is what they should be, given that they are Excel files).
I would like to either (a) read all the excels in as data frame, or (b) create a loop that coerces each of the lists into a data frame.
I have tried several approaches for (b) but none have worked, for example lapply(read_files, as.data.frame)
. I have only managed to coerce individual lists into data frames, for example by doing as.data.frame(read_files[1])
.
Any help would be greatly appreciated!