简体   繁体   中英

Reading multiple excel files as one data frame/table

I want to combine excel files together using R, and facing few issues: 1- I create a list of the files, so far only .xlsx as i want less problems for now. A <- list.files(pattern = '.xlsx', recursive = TRUE)

2- B <- lapply(A, read.xlsx) I get an error: (Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 92, 96, 76, 88).

3- Another problem has to do with columns type.

Error: Can't combine `..1$Ct.(dR)` <double> and `..7$Ct.(dR)` <character>.

I know usually how to use as.character, but since I have a list not an actual file, I am clueless.

*My plan is as follows: -make list -> read them as excel files -> combine them into one file/table/df/matrix -> then visualize data

*My problems:

  • column type different
  • inconsistent raw, column numbers between files

Any help is appreicated. I know that this has been asked before but unfortunately I was unable to replicate what was mentioned in the other questions&answers.

To troubleshoot this, you can print out the name of the file inside of the lapply :

B <- lapply(A, function(x) {
   print(paste0("reading file: ", x))
   read.xlsx(x)
})

Once you you know which file causes the problem, you can provide more details and possibly a repex .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM