将excel文件(xls)导入R

时间:2014-04-04 13:27:15

标签: r excel statistics

我尝试将我的文件插入R.但我总是遇到问题

Warning messages:
1: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
  [RODBC] ERROR: state HY000, code -5016, message [Microsoft][ODBC Excel Driver] Reserved error (-5016); there is no message for this error.
2: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
  [RODBC] ERROR: state 01000, code 1, message [Microsoft][ODBC Excel Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x1c68 Thread 0xe00 DBC 0xe398d8c Excel'.
3: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
  ODBC connection failed

我的代码是:


myfile<-"ds616.xls"
library(RODBC)
channel <- odbcConnectExcel(myfile)
sqlTables(channel)
mydataframe <- sqlFetch(channel, "sheet1")
odbcClose(channel)

我检查它不能运行第3行。请帮助我。我检查路径。这很好。

但它仍然是错误的。

2 个答案:

答案 0 :(得分:0)

编辑:OP正在使用32位Windows,但对于在64位Windows下遇到RODBC问题的用户,此答案仍可能提供信息。

由于缺少驱动程序,

RODBC在Windows 64位下无效。 我在64位Windows下了解的唯一解决方案是将.xls保存为.csv并使用read.csv进行导入。

答案 1 :(得分:0)

您使用的是RStudio吗?

在RStudio中工作时经常遇到这个错误:

R version 3.1.0 (2014-04-10)
    Platform: i386-w64-mingw32/i386 (32-bit)

    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     

    other attached packages:
    [1] FWDselect_1.1 mgcv_1.7-29   nlme_3.1-117  stringr_0.6.2 sas7bdat_0.4  chron_2.3-45  RODBC_1.3-10 

虽然我无法确定RODBC软件包无法连接到Excel的确切原因,但请尝试在简单R中重新运行代码。至少这是一种解决方案,直到进一步调查为止

相关问题