我试图用这个链接'https://www.ons.gov.uk/file?uri=/economy/grossvalueaddedgva/datasets/regionalgvaibylocalauthorityintheuk/1997to2015/regionalgvaibylainuk.xls'打开包含'xlsx'的.xls文件,但它似乎没有用。我也试过像'gdata'这样的其他包也没成功。
install.packages('xlsx')
require('xlsx')
file <- system.file('https://www.ons.gov.uk/file?uri=/economy/grossvalueaddedgva/datasets/regionalgvaibylocalauthorityintheuk/1997to2015/regionalgvaibylainuk.xls', package = "xlsx")
res <- read.xlsx(file, 5) # read the fifth sheet
我收到此错误:'loadWorkbook中的错误(文件,密码=密码):找不到'
我也尝试过read.xls()函数,但它也引发了一个错误。
我想Read Excel file from a URL using the readxl package的答案可以在这里使用:
library(httr)
library(xlsx)
url1<-'https://www.ons.gov.uk/file?uri=/economy/grossvalueaddedgva/datasets/regionalgvaibylocalauthorityintheuk/1997to2015/regionalgvaibylainuk.xls'
GET(url1, write_disk(tf <- tempfile(fileext = ".xls")))
res <- read.xlsx(tf, 5)