在R中合并多个.xls文件 [英] Merging multiple .xls files in R

查看:63
本文介绍了在R中合并多个.xls文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google驱动器中合并 .xls 文件的列表.现在,我已经设法创建了我需要的所有文件的列表,但是由于某种原因,我仍然无法合并它们,这是到目前为止的代码:

I am trying to merge a list of .xls files in google drive. I have now managed to create a list of all the files I need, but for some reason I still can't manage to merge them, this is the code I have so far:

library(googledrive)
inputfiles <- drive_ls(path = "Email It In", pattern = "*PDOL_dataexport", n_max = 50)

library(readxl)
df.list<- lapply(inputfiles,function(x) read_xls(x))
library(dplyr)
consolidated_data<-bind_rows(df.list)

代码的第二部分引发以下错误:

The second part of the code throws up the following error:

Error: `path` must be a string 

我必须错误地输入路径(输入文件),有人可以帮忙吗?

I must be entering the path (inputfiles) incorrectly for lapply, can someone please help?

推荐答案

我发现导入.xlsx文件或.xls文件时,readxl软件包更加友好.假设每个.xls文件仅包含一张要导入的工作表,则下面的代码应该可以为您工作.

I have found readxl package to be more friendly when importing .xlsx files or .xls files. Assuming each of the .xls file contains just one sheet to be imported the below code should work for you.

library(googledrive)

drive_find(n_max = 50)

library(readxl)

inputfiles <- list.files(pattern = "*PDOL_dataexport")

df.list<-lapply(inputfiles ,function(x) read_xls(x))

library(dplyr)

consolidated_data<-bind_rows(df.list)

这篇关于在R中合并多个.xls文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆