[R] Putting a bunch of Excel files as data.frames into a list fails

G.Maubach at weinwolf.de G.Maubach at weinwolf.de
Wed Sep 28 17:02:17 CEST 2016


Hi All,

I need to read a bunch of Excel files and store them in R.

I decided to store the different Excel files in data.frames in a named 
list where the names are the file names of each file (and that is 
different from the sources as far as I can see):

-- cut --
# Sources:
# - 
http://stackoverflow.com/questions/11433432/importing-multiple-csv-files-into-r
# - 
http://stackoverflow.com/questions/9564489/opening-all-files-in-a-folder-and-applying-a-function
# - 
http://stackoverflow.com/questions/12945687/how-to-read-all-worksheets-in-an-excel-workbook-into-an-r-list-with-data-frame-e

v_file_path <- "H:/2016/Analysen/Neukunden/Input"
v_file_pattern <- "*.xlsx"

v_files <- list.files(path = v_file_path,
                      pattern = v_file_pattern,
                      ignore.case = TRUE)
print(v_files)

v_list_of_files <- list()

for (v_file in v_files) {
  v_list_of_files[v_file] <- openxlsx::read.xlsx(
    file.path(v_file_path,
              v_file))
}

This code does not work cause it stores only the first variable of each 
Excel file in a named list.

What do I need to change to get it running?

Kind regards

Georg



More information about the R-help mailing list