0

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.

Maik
  • 310
  • 1
  • 11
Ahmad
  • 23
  • 4
  • Does this answer your question? [How to import multiple .csv files at once?](https://stackoverflow.com/questions/11433432/how-to-import-multiple-csv-files-at-once) – Bulat Sep 14 '20 at 10:36
  • you need to use this `list.files(pattern='*.xlsx')` with `*` mask? – Bulat Sep 14 '20 at 10:42

1 Answers1

0

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.

Bulat
  • 6,869
  • 1
  • 29
  • 52