In followup to this post: Import multiple excel sheets using openxlsx , I would like to import multiple sheets from multiple xlsx files into one R data frame using openxlsx (or any other package that isn't sported by Java due to memory problems).
At the moment my code looks like this:
require(openxlsx)
file.list <- list.files(recursive=T,pattern='*.xlsx')
for (i i 1:length(file.list)){
wb <- loadWorkbook(file.list[i]) #select a file & load workbook
sheet <-sheets(wb) #get sheet list
for (j in 1:length(sheet)){
tmp<-read.xlsx(file.list[i], sheet=j, cols= c(1:4,6,7,9:12,14,15,17:30),
startRow=5, skipEmptyRows = T, colNames=F)
tmp$file = i
if (i==1&j==1) dataset<-tmp else dataset<-rbind(dataset,tmp)
}
}
However the rbind function returns the following error
Error in rbind(deparse.level, ...) :
numbers of columns of arguments do not match
I think that my mistake lays somewhere in the read.xlsx code but I can't figure out where I'm going wrong.
Any help or suggestions are very welcome!