我希望R读取具有多个工作表的多个xlsx文件,每个文件的第一工作表都有一个标头(名称),但其余工作表没有任何标题,但是完全相同的列。某些工作表的列为空,但需要将其视为NA值 我试过了,它确实读取了文件,但最终数据帧中有错误,某些单元格中不存在NA的值 任何人有想法或替代解决方案? 谢谢
library(readxl)
#Set path
inputFolder <- "test/"
#Get list of files
fileList <- list.files(path = inputFolder, recursive=T, pattern='*.xlsx')
#Read in each sheet from each excel
for (f in 1:length(fileList)){
#Find the number of sheets in this workbook
sheetList <- excel_sheets(paste(inputFolder, fileList[f], sep = ""))
#Get the sheets of this workbook
for (s in 1:length(sheetList)) {
tempSheet <- read_excel(paste(inputFolder, fileList[f], sep = ""), sheet = sheetList[s])
if (f == 1 & s == 1) {
df <- tempSheet
}
else {
if(s != 1) {
names(tempSheet) <- names(df)
}
df <- rbind(df,tempSheet)
}
}
}