0

I use list apply to simultaneously import multiple (hundreds) of excel files ( using read_excel funtion to import specific cell range) into R followed by rbind.fill to build a single r dataframe and has always worked. However, this time one a (same name) variable (which is a date) has two different formats in different excel files. In some files is a double (POSIXct)and others is a character. I think I need to first get them to the same format before importing??? Don't know how to do it. Hope someone can help. Much appreciated.

I tried using multiple function (concatenate read_excel with as.character) and then rbind.fill and got the message that "ALL Inputs to r.bind must be data frames"

r2evans
  • 141,215
  • 6
  • 77
  • 149
Daniel
  • 1
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jan 19 '23 at 13:30
  • (1) I hope you're really using `lapply` and not `apply`, the latter is less-suited for this purpose. (2) Please be explicit about non-base packages, I'm inferring `plyr` and `readxl`. Are there others that are meaningful here? (3) For the different formats of dates, see https://stackoverflow.com/a/52319606/3358272, it handles (I believe _exactly_) the conditions you describe. – r2evans Jan 19 '23 at 13:45
  • # Create list of file paths file.Paths <-list.files(file.path(data_dir,"Input Data") , full.names = TRUE) # Import Excel files for specific cell range import.list <- lapply(file.Paths, function(x) read_excel(x, range = "Sheet1!A1:AD55")) #Combine to create dataframe (df) Agregated.df <- rbind.fill(import.list) #These 2 steps always worked, however this time a specific variable(Date) is either in character or double format in different sheets. # I believe I need to change the format (to character?) of within or previous to the process of importing multiple excel files. ??? – Daniel Jan 20 '23 at 11:16

0 Answers0