从R中的NOAA下载选择文件

问题描述 投票:0回答:1

我有一个我在NOAA网站上找到的文件列表,其中包含以下URL:

https://www.ncei.noaa.gov/data/gsoy/access/

我想知道如何从这里只将特定文件加载到R中。

r csv noaa
1个回答
0
投票

这将是一个你将它视为FTP的情况。

library(RCurl)
url = "https://www.ncei.noaa.gov/data/gsoy/access/"
filenames = getURL(url, dirlistonly = TRUE)
filenames <- strsplit(filenames, "\r\n")
filenames <- unlist(filenames)

download_filenames <- c("ZI000067781.csv", "ZI000067755.csv") #specify what files you want, do this in whatever way you desire, with a regex, list, etc.


sapply(download_filenames, function(x) {
  download.file(paste(url, filename, sep = ""), paste(getwd(), "/", filename,
                                                                                        sep = ""))
}) #apply a download to your file names

您也可以连续将您想要的csv读入数据帧。就像MrFlick说的那样,不确定你究竟想要什么。

© www.soinside.com 2019 - 2024. All rights reserved.