Sys.setlocale("LC_ALL","Chinese")
library("XLConnect")
library("plyr")
path <- list.files("E:/jichushuju/yuebao/")
GDP <- lapply(path[1:15], readWorksheetFromFile, "综合—GDP",
header = TRUE, startCol = 1,
startRow = 2, endCol = 8,
endRow = 39)
add <- function(x) Reduce(rbind.fill, x)
GDP.all <- add(GDP)
write.csv(GDP.all,"GDP.csv")
# 以上程序表示循环从15个excel工作簿中读出名为“综合—GDP”这张表,并写到一张表中;
sheets <- c("综合—GDP","综合-财政收入","综合-财政支出","综合—新增市场主体",
"产业发展——金融","对外开放-外资","对外开放-外贸","招商项目1","招商项目2")
# 现在我需要从同样15张表中分别读入表名如上所述的9张表,并分别写到对应的表格中;
yuebao3 <- lapply(path[1:15], readWorksheetFromFile, sheets[1],
header = TRUE, startCol = 1,
startRow = 2, endCol = 8,
endRow = 39)
# 在循环外引用sheets[1],程序运行正常;
yuebao <- lapply(path[1:15], readWorksheetFromFile, sheets,
header = TRUE, startCol = 1,
startRow = 2, endCol = 8,
endRow = 39)
for (i in 2:length(sheets)){
yuebao1 <- lapply(path[1:15], readWorksheetFromFile, sheets,
header = TRUE, startCol = 1,
startRow = 2, endCol = 8,
endRow = 39)
yuebao <- list(yuebao,yuebao1)
}
# 运行这个循环时,总是提醒第二行出错“debug at #2: yuebao <- lapply(path[1:15], readWorksheetFromFile, sheets,
header = TRUE, startCol = 1, startRow = 2, endCol = 8, endRow = 39)”
请教一下,怎么解决这个问题?
另外,能不能给一个同时合并多个excel表格更好的解决办法?
谢谢。