在 R 中提取 WorldClim 数据,但缺少几个月

Extracting WorldClim data in R but some months are missing

我有一个关于在 R 中提取 WorldClim 数据的问题并得到了很好的帮助 ()

该解决方案工作正常,但我现在面临一个单独的问题。

我执行以下代码以.cvs 格式提取并保存 WorldClim 月度最低温度数据

library(sp)
library(rgeos)
library(rgdal)
r<- getData('CMIP5', var='tmin', res=10, rcp=45, model='HE', year=70)
r <- r[[c(1,12)]]
poly <- shapefile("C:/Users/pc5/Desktop/r1//2011_Dist.shp")
plot(poly)
pr <- extract(r, poly, fun='mean', na.rm=TRUE, df=TRUE, weights = TRUE) 
write.csv(cbind(poly$DISTRICT,ex),"Worldclim.csv", row.names = F)

然而,当我提取并保存数据时,我只得到三个变量:DISTRICT 名称、第 1 个月的 TMIN 和第 12 个月的 TMIN。 我看到当我 运行 代码

ex <- extract(r, poly, fun='mean', na.rm=TRUE, df=TRUE, weights = TRUE) 

虽然我可以看到所有 12 个月的数据都以 Geotiff 格式下载到默认文件夹中,但它仅提取 3 个变量而不是 13 个(12 个月 + I 地区名称)。我做错了什么?

运行没有r <- r[[c(1,12)]]的代码,你会得到想要的结果。 r <- r[[c(1,12)]] 部分代码仅从 12 个月数据的栅格堆栈中删除 1 个月和 12 个月。您可以通过以下代码确定

r<- getData('CMIP5', var='tmin', res=10, rcp=45, model='HE', year=70)
r #will show you dimensions  : 900, 2160, 1944000, 12  (nrow, ncol, ncell, nlayers)
r1 <- r[[c(1,12)]]
r1 #will show you dimensions  : 900, 2160, 1944000, 2  (nrow, ncol, ncell, nlayers)
plot(r) #Plot of all the 12 months
plot(r1) #Plot of only 1 and 12 month

我也编辑了我之前的回答。