我想从 https://archive.ics.uci.edu/dataset/312/dow_jones_index 导入数据。我不知道如何从新版本的网站导入数据。
过去我能做到
ds <- read.csv(file = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00451/dataR2.csv',
header = TRUE)
但我不明白在这里该怎么做。如何在不下载 zip 文件的情况下导入到 R?
原来你无法直接获取数据文件,你需要下载zip文件然后解压,然后读取表格。
# URL
url <- "https://archive.ics.uci.edu/ml/machine-learning-databases/00312/dow_jones_index.zip"
# Download and unzip the dataset
temp <- tempfile()
download.file(url, temp)
unzip(temp, exdir = ".")
unlink(temp) # Remove temporary file
# Import dataset into a dataframe
df <- read.table("dow_jones_index.data", sep = ',')
# View the first few rows of the dataframe
head(df)