Merging multiple .xls files in R [duplicate]

北战南征 提交于 2020-12-13 04:14:34

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/54595433/merging-multiple-xls-files-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!