How can I read an Excel file directly into R? Or should I first export the data to a text- or CSV file and import that file into R?
Expanding on the answer provided by @Mikko you can use a neat trick to speed things up without having to "know" your column classes ahead of time. Simply use read.xlsx
to grab a limited number of records to determine the classes and then followed it up with read.xlsx2
Example
# just the first 50 rows should do...
df.temp <- read.xlsx("filename.xlsx", 1, startRow=1, endRow=50)
df.real <- read.xlsx2("filename.xlsx", 1,
colClasses=as.vector(sapply(df.temp, mode)))