我使用R来导入RODBC包的数据。问题是我使用的Excel文件在表名中有重点,我需要弄清楚如何导入数据而无需手动更改电子表格的名称。
以下是该问题的可重现示例:
download.file("http://www.secretariadoejecutivo.gob.mx/docs/datos_abiertos/Datos_abiertos_Victimas_Fuero_comun.xls",
destfile="./Victimas_Fuero_comun.xls",
mode = "wb")
library(RODBC)
filePath <- "./Victimas_Fuero_comun.xls"
channel <- odbcConnectExcel2007(filePath)
sqlTables(channel)
DatosAbiertosVictimasFuero <- sqlFetch(channel,
"Datos_abiertos_Víctimas_Fuero_c") # accent in 'Víctimas'
odbcClose(channel)
str(DatosAbiertosVictimasFuero )
sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RODBC_1.3-13
答案 0 :(得分:0)
这很有用
library(readxl)
filePath <- "./Victimas_Fuero_comun.xls"
data <- read_excel(filePath, sheet = 1)