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

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

Re: [R] Creating a year-month indicator and groupby with category

2022-10-03 Thread Tariq Khasiri
Thanks everyone for being so kind and patient with me throughout the process! Mr. Barradas and Mr. Lemon, very generous of you for taking the time and patience to go over my code and data , and taking the time to give me meaningful feedback! With your help and suggestion, I was successful in

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 =

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

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

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),

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.

[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

Re: [R] Creating a year-month indicator and groupby with category

2022-10-03 Thread Jim Lemon
Hi Tariq, There were a couple of glitches in your data structure. Here's an example of a simple plot: dat<-structure(list(year = c(2018, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2017, 2018, 2018, 2018, 2018, 2018, 2018, 2018,