2 年内无需环拉单个气象站。相反,使用end_date=
参数。由于您从 2015 年 1 月 1 日开始,因此结束日期将为 2016 年 12 月 31 日。
library(weatherData)
weather<-getWeatherForDate("IMUU011F4", "2015-01-01", "2016-12-31",
station_type="id",
opt_detailed=T, opt_custom_columns=T,
custom_columns= c(3,7,9))
下载过程会向 R 控制台写入大量数据,从以下内容开始:
Checking Data Availability For IMUU011F4
Found 141 records for 2015-01-01
Found 145 records for 2016-12-31
Data is Available for the interval.
Will be fetching these Columns:
[1] "Time" "DewpointF" "WindSpeedMPH" "Humidity"
Begin getting Daily Data for IMUU011F4
IMUU011F4 1 2015-01-01 : Fetching 282 Rows with 4 Column(s)
IMUU011F4 2 2015-01-02 : Fetching 305 Rows with 4 Column(s)
IMUU011F4 3 2015-01-03 : Fetching 313 Rows with 4 Column(s)
IMUU011F4 4 2015-01-04 : Fetching 253 Rows with 4 Column(s)
IMUU011F4 5 2015-01-05 : Fetching 318 Rows with 4 Column(s)
IMUU011F4 6 2015-01-06 : Fetching 319 Rows with 4 Column(s)
IMUU011F4 7 2015-01-07 : Fetching 335 Rows with 4 Column(s)
IMUU011F4 8 2015-01-08 : Fetching 349 Rows with 4 Column(s)
IMUU011F4 9 2015-01-09 : Fetching 332 Rows with 4 Column(s)
IMUU011F4 10 2015-01-10 : Fetching 344 Rows with 4 Column(s)
.
.
.
生成的数据框如下所示。
> nrow(weather)
[1] 203015
> summary(weather)
Time DewpointF WindSpeedMPH Humidity
Min. :2015-01-01 00:04:00 Min. : 5.40 Min. : 0.000 Min. : 0.00
1st Qu.:2015-06-27 18:01:30 1st Qu.:47.20 1st Qu.: 0.000 1st Qu.:58.00
Median :2015-12-18 11:18:00 Median :54.90 Median : 5.400 Median :69.00
Mean :2015-12-26 23:42:55 Mean :54.36 Mean : 5.877 Mean :68.73
3rd Qu.:2016-06-24 00:42:00 3rd Qu.:64.40 3rd Qu.: 9.200 3rd Qu.:80.00
Max. :2016-12-31 23:58:00 Max. :78.80 Max. :43.400 Max. :99.00
> head(weather)
Time DewpointF WindSpeedMPH Humidity
1 2015-01-01 00:04:00 51.0 11.4 89
2 2015-01-01 00:11:00 51.0 13.0 89
3 2015-01-01 00:17:00 51.0 15.2 89
4 2015-01-01 00:22:00 51.0 8.3 89
5 2015-01-01 00:27:00 51.5 11.4 90
6 2015-01-01 00:32:00 51.5 9.2 90
>
如果你想获取多个气象站的天气,这可以通过一个apply()
函数来完成。请注意,这将需要几分钟的时间来执行,因为 IMUU011F4 气象站为 2 年的数据请求生成了超过 203,000 行的输出。
theStations <- c("IMUU011F4","KFLMIAMI75","IMOSCOWO2")
weatherList <- lapply(theStations, function (x) {
getWeatherForDate(x, "2015-01-01", "2016-12-31",
station_type="id",
opt_detailed=T, opt_custom_columns=T,
custom_columns= c(3,7,9))
})
weather <- do.call(rbind,weatherList)