测试各种方法读取xlxs文件

测试各种方法读取xlxs文件

此文参考:http://www.milanor.net/blog/?p=779

  • Save Excel files into csv file

> # Method 1 transform to csv format

> # Start the clock!

> ptm <- proc.time()

> T2 <- read.csv("weather_data_2012.csv", header = TRUE)

> # Stop the clock

> proc.time() - ptm

user system elapsed

0.06 0.00 0.06

 

  • ODBC

 

Nowadays it still support only 32 bit versions of R and this limit discourage the use of this package. Besides Microsoft Windows and 32-bit R, it requires the Excel ODBC driver installed.

 

  • gdata package

    strawberry-perl is need to be installed in the computer. and peal location should be noted in the code.

> # Method 2

> library(gdata)

> # Start the clock!

> ptm <- proc.time()

> T3 <- read.xls("weather_data_2012.xlsx", sheet = 1, header = TRUE, perl="C:/strawberry/perl/bin/perl.exe")

> # Stop the clock

> proc.time() - ptm

用户 系统 流逝

0.12 0.01 5.86

 

  • xlsReadWrite package

 

xlsReadWrite is reported here for didactically purposes only although it is very fast: it doesn't support .xlsx files and this is not acceptable nowadays.

 

  • XLConnect package

 

XLConnect is a Java-based solution, so it is cross platform and returns satisfactory results. For large data sets it may be very slow.

> library(XLConnect)

> # Start the clock!

> ptm <- proc.time()

> wb <- loadWorkbook("weather_data_2012.xlsx")

> T4 <- readWorksheet(wb, sheet = "Sheet1", header = TRUE)

> # Stop the clock

> proc.time() - ptm

user system elapsed

3.24 0.01 0.81

 

***to use this package xlsx package should be unloaded first.

 

  • xlsx package

 

xlsx package read (and write) .xlsx and .xls files using Java. It is cross platform and uses rJava to deal with Java. Java should be installed in the computer first. This method is very slow.

 

> detach("package:XLConnect", unload=TRUE)

> library(xlsx)

> # Start the clock!

> ptm <- proc.time()

> T1 <- read.xlsx("weather_data_2012.xlsx",1)

> # Stop the clock

> proc.time() - ptm

用户 系统 流逝

50.02 0.02 48.24

posted @ 2014-06-23 14:08  此间漫步  阅读(597)  评论(0编辑  收藏  举报