简体   繁体   English

将多个excel文件作为一个数据框/表格读取

[英]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.我想使用 R 将 excel 文件组合在一起,并面临几个问题:1- 我创建了一个文件列表,到目前为止只有 .xlsx,因为我现在想要更少的问题。 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). 2- B <- lapply(A, read.xlsx)我得到一个错误: ((function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : 参数暗示不同行数:92、96、76、88)。

3- Another problem has to do with columns type. 3- 另一个问题与列类型有关。

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.我通常知道如何使用 as.character,但由于我有一个列表而不是实际文件,所以我一无所知。

*My plan is as follows: -make list -> read them as excel files -> combine them into one file/table/df/matrix -> then visualize data *我的计划如下:-制作列表->将它们作为excel文件读取->将它们组合成一个文件/表/df/矩阵->然后可视化数据

*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 :要解决此问题,您可以打印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 .一旦您知道是哪个文件导致了问题,您就可以提供更多详细信息,并可能提供repex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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