我无法使用readxl打开/读取从澳大利亚统计局网站下载的excel文件。
我已经从网站上downloaded Table 12了,但是当我去阅读r
中的工作簿表时,我收到一条错误消息:
library(readxl)
excel_sheets(path = "C:/Users/Name/Documents/downloaded_file.xls")
"Error in xls_sheets(path) : Failed to open C:/Users/Name/Documents/downloaded_file.xls".
在readxl
的早期版本中,我很容易将这些文件读取到r
中,但是经过几个月的中断,我最近更新了自己的readxl版本,但现在不起作用了。
我尝试使用download.file
函数下载文件,但要小心设置mode = wb
,但这对访问工作簿中的数据也没有影响。
感谢任何指针。
答案 0 :(得分:0)
您是否尝试过其他软件包。如果我手动下载文件并使用xlsx
进行读取,那么它对我有用。在ouptut下方是您需要的东西,还是我缺少什么?
library("xlsx")
# there is certainly a better (faster) way to get the sheet number
n_sheets = length(getSheets(loadWorkbook("6202012.xls")))
# if you know which sheet to load, reading the sheet works for me...
df = read.xlsx("6202012.xls", 2)
df[1:3, 1:3]
# NA. Employed.total....Persons....Australia.. Employed.total....Persons....Australia...1
# 1 Unit 000 000
# 2 Series Type Trend Seasonally Adjusted
# 3 Data Type STOCK STOCK
答案 1 :(得分:0)
它在Windows上适用:
library(readxl)
excel_sheets(path = "C:/Users/Name/Documents/downloaded_file.xls")
data<-readxl::read_excel(path = ""C:/Users/Name/Documents/downloaded_file.xls"",sheet = "Data1")