I am trying to read in a number of Excel files into R using read.xlsx
using the xlsx
package but when I do so I am getting the following error:
Error in
loadWorkbook(file)
: Cannot find id100.xlsx
First I list the files in the directory:
> files <- list.files(datDir, pattern = ".xlsx")
Then I use read.xlsx
to read them all in:
for (i in seq_along(files)) {
assign(paste("id", i, sep = "."), read.xlsx(files[i],1,as.data.frame=TRUE,
header=FALSE, stringsAsFactors=FALSE, na.strings=" "))
}
I checked to see if the file was even in the list and it is:
> files
[1] "id100.xlsx" "id101.xlsx" etc...
> files[1]
[1] "id100.xlsx"
I have used this code many times before today and for some reason it is just not working. I keep getting that error. Does anyone have any suggestions?
Thanks!
如果您的工作目录与datDir不同,您应该使用full.names=T
如下所示:
files <- list.files(datDir, pattern = ".xlsx",full.names=T)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.