批量读文件夹excel
first_category_name = list.files("./Documents/礼县附件二/")
#list.files命令得到文件夹下所有文件夹的名称【修改】
dir = paste("./Documents/礼县附件二/",first_category_name,sep="")
#用paste命令构建路径变量dir,
n = length(dir)
datalist = list()
for(i in 1:n){
if(str_detect(dir[i],'xlsx')){
datalist[[i]]=readxl::read_xlsx(dir[i],skip = 3)
}
else{
datalist[[i]]=readxl::read_xls(dir[i],skip = 3)
}
}
nrows=sapply(datalist, nrow)
sum(nrows)
n = length(dir)
i=17
datalist = data.frame()
if (str_detect(dir[i], 'xlsx')) {
datalist = readxl::read_xlsx(dir[i], skip = 2, sheet = 1)
} else {
datalist = readxl::read_xls(dir[i], skip = 2, sheet = 1)
}
评论
发表评论