Re: [R] automatic convert list to dataframe

2022-10-03 Thread Kai Yang via R-help
Hello Rui and Bert, This is a great help! Thank you both! Here is my job assignment: boss accumulate many years excel reports from same lab. Each report contents multiple data sheets. Those sheets may/may not updated, and some sheets are new. Good news is, the same testing result data will be s

Re: [R] automatic convert list to dataframe

2022-10-03 Thread Bert Gunter
... But why not dispense with multiple files, name juggling, and environments by simply putting everything in one list of lists (lists are recursive structures!): all_files <- lapply(filenames, function(nm)import_list(nm,...)) names(all_files) <- filenames ## Note: the ... are any optional paramet

Re: [R] automatic convert list to dataframe

2022-10-03 Thread Rui Barradas
Hello, Here are two more attempts at solving the problem. 1. Instead of having 30-40 data.frames per file in the globalenv, not a good idea, the following code will create as many lists as you have files and each list is a list of df's. temp_list <- vector("list", length = length(filenames)

Re: [R] automatic convert list to dataframe

2022-10-03 Thread Kai Yang via R-help
Hi Rui, I copied "list2env(i, envir = .GlobalEnv)" to the code, but I got the same error message of "first argument must be a named list". Maybe list2env cannot put in loop? the code works very well outside of for loop. One more thing, the difference file may have same sheet name. that's why I w

Re: [R] automatic convert list to dataframe

2022-10-03 Thread Rui Barradas
Hello, If in each iteration i is a list, try removing the call to names(). Try, in the loop, list2env(i, envir = .GlobalEnv) The error message is telling that list2env's first argument must be a named list and names(i) is an unnamed vector, it's i that's the named list (you even changed its

Re: [R] automatic convert list to dataframe

2022-10-03 Thread Kai Yang via R-help
Hi Rui, list2env(file1, envir = .GlobalEnv) is worked very well. Thank you. But when I tried to put the sample code  into for loop. I got error message: for(i in filenames){   assign(i, import_list(paste0(i, ".xlsx", sep="")))   names(i) <- paste(i, names(i), sep = "_")   list2env(names(i), envir

Re: [R] automatic convert list to dataframe

2022-10-03 Thread Rui Barradas
Hello, list2env(file1, envir = .GlobalEnv) will create data.frames dx1, dx2, etc, in the global environment. If you really need the names file1_dx1, file1_dx2, etc, you can first change the names names(file1) <- paste("file1", names(file1), sep = "_") and then run list2env like above. H

[R] automatic convert list to dataframe

2022-10-03 Thread Kai Yang via R-help
Hi R team, I can use rio package to read excel file into R as a list. The excel file content multiple sheets (30 - 40 data sheets). I can convert each data elements into dataframe manually. I have multiple excel files with multiple data sheets. I need to load them into R and do the comparison fo