将位于子文件夹中的Excel文件同样命名为R中并绑定
我正在寻找一种解决方案,将几个位于几个子文件
夹中的excel文件加载到R中。 :
setwd('C:\Users\RandomGuy\Workspace\')
dir()
combination <- dir()[grepl('MZB', dir())]
# loop
for (i1 in 1:length(combination)) print(readxl::excel_sheets(combination[[i1]])); rm(i1)
# checking of
comb <- list()
for (i1 in 1:length(combination)) {
comb[[i1]] <- readxl::read_xlsx(combination[[i1]], sheet='')
print(names(comb[[i1]])) }; rm(i1)
comb <- do.call('rbind', comb)
现在,我有一个问题,那些Excel文件不是位于同一文件夹中的,而是在几个子文件夹中。 是否有方法可以访问这些方法并将同样命名为Excel文件(或一次至少一个表)合并到R中?
I am searching for a solution to load several equally named Excel files located in several subfolders into R.
When those excel files were located in the same folder and all contain "MZB" as part of their name, I could easily apply a loop such as:
setwd('C:\Users\RandomGuy\Workspace\')
dir()
combination <- dir()[grepl('MZB', dir())]
# loop
for (i1 in 1:length(combination)) print(readxl::excel_sheets(combination[[i1]])); rm(i1)
# checking of
comb <- list()
for (i1 in 1:length(combination)) {
comb[[i1]] <- readxl::read_xlsx(combination[[i1]], sheet='')
print(names(comb[[i1]])) }; rm(i1)
comb <- do.call('rbind', comb)
Now, I have the issue, that those excel files are not located in the same folder but instead in several subfolders.
Is there are way to access those and merge equally named Excel files (or at least one sheet at a time) into R?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)