The read.xls
function in the gdata
package will read the xlsx
and xls
files in R
I often use this.
It looks like you have a lot of Excel files to work with, here is what I am doing to get a large number of these files (both xlsx
and xls
) in R
:
Setting up work directly with the location of Excel files
setwd("F:\\ address of folder with all my Excel files")
List all files in the working directory
MyFiles <- list.files()
Check list
MyFiles
Makeke list containing all the data from the xls and xlsx files contained in the working directory. This is similar to the batch data import function.
library(gdata) Mylist <- lapply(MyFiles, read.xls)
Make sure that it reads all the files in the folder if some Excel files are corrupted, etc. If the result is FALSE
, a problem occurs.
identical(length(MyFiles), length(Mylist))
Then I continue to work with sapply
, etc. to perform functions according to data in files.
source share