在R中,我如何下载数据集?



我正试图将民意调查数据下载到R中进行一些回归。我如何在R中下载它?我正试图从CSV表单下载ANES数据。由于某些原因,它现在不能工作。

我试图下载它从:https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/FXGD96或https://electionstudies.org/data-center/2016-time-series-study/当我试图打开它,我下载CSV,我得到错误消息。

我以前试过,但是我的数据集不再工作了。

很抱歉我不擅长stackoverflow,我是新手。

您需要在得到错误之前使用的代码后面包含所有错误消息的全文。

https://electionstudies.org/data-center/2020-time-series-study/链接的网页允许您通过单击带有文件类型文本标签的图标来选择文件类型。当我点击2020年选举页面上的CSV图标时,它实际上是将我发送到https://electionstudies.org/anes_timeseries_2020_csv_20220210/。该页面有代码,自动希望我下载的不是CSV文件,而是zip文件。

download.file( url = "https://electionstudies.org/anes_timeseries_2020_csv_20220210/" , 
dest = "~/Downloads/2020ANES.zip")  #name of destination
#trying URL 'https://electionstudies.org/anes_timeseries_2020_csv_20220210/'
#Content type 'application/x-zip-compressed' length 7777954 bytes (7.4 MB)
#=====builds a progress bar ========================
# downloaded 7.4 MB   (completion message appears)

然后,您需要使用系统工具或r函数从zip文件中提取数据。

最新更新