r - 如何在 r 中合并多张 Excel 工作簿?

标签 r excel dataframe merge google-sheets

关闭。这个问题需要debugging details .它目前不接受答案。












编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将帮助其他人回答问题。


5年前关闭。







Improve this question




假设我有一个名为 report.xlsx 的 excel 文件。该文件有 10 张,方便地命名为 Sheet1 到 Sheet10。在每张纸上,第 14 行有列标题:S/N、RegistryNr、Surname、FirstName、(空)、FatherName、MotherName、sex、(空)、DOB。如何将每张工作表合并到一个数据集中?

我知道 excel_sheets("report.xlsx")我可以将所有工作表名称放入一个向量中。

我知道 df <- read_excel("report.xlsx", 1, skip = 14)我可以将一张纸的所有数据放入数据框df。

这就是我对 R 的了解程度:/

如何结合上述命令将每张工作表导入同一个数据框中?

最佳答案

我通常使用 purrr 和 readxl 来执行此操作:

library(purrr)
library(readxl)

file <- 'path to report.xlsx'

sheets <- excel_sheets(file)

df <- map_df(sheets, ~ read_excel(file, sheet = .x, skip = 14))

关于r - 如何在 r 中合并多张 Excel 工作簿?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40550415/

相关文章:

r - 如何在 dplyr 中使用 recode_factor 来重新编码多个因子值?

r - R 中的 Knn 回归

r - 为 R 中文件夹中的所有文件添加文件扩展名

excel - 保护工作表时无法使用超链接,不允许用户选择锁定的单元格

python - 对 Pandas DataFrame 列表求和

r - 如何使用 r 中的 igraph 分别计算不同时期的网络测量值?

sql - Excel 中 SQL 表的动态查询

excel - 从长日期 - 时间格式中提取日期

python - 计算按特定列分组的项目之间的平均时间差

python - 如何用 Pandas 选择重复的行?