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

jeremiah rounds roundsjeremiah at gmail.com
Wed Sep 28 20:21:31 CEST 2016


Try changing:
v_list_of_files[v_file]
to:
v_list_of_files[[v_file]]

Also are you sure you are not generating warnings? For example,
 l = list()
l["iris"] = iris;

Also, you can change it to lapply(v_files, function(v_file){...})


Have a good one,
Jeremiah

On Wed, Sep 28, 2016 at 8:02 AM, <G.Maubach at weinwolf.de> wrote:

> 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
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list