如何将栅格对象提取或子集化为一行数据?我有一个全球温度数据栅格,并想计算每个经度/列的每年平均月值。
library(ncdf4)
library(raster)
download.file("http://www.cru.uea.ac.uk/cru/data/temperature/CRUTEM.4.3.0.0.anomalies.nc"
, destfile="CRUTEM.4.3.0.0.anomalies.nc", mode="wb")
cru.tmp <- stack("CRUTEM.4.3.0.0.anomalies.nc")
# inspect elements
cru.tmp
# list all years
names(cru.tmp)
# plot a single year
plot(cru.tmp$X2008.01.16)
# find nrow for 67.5deg North
mylat <- rowFromY(cru.tmp, 67.5)
# extract the row
cru.tmp.67.5N <- getValuesBlock(test, row=mylat, nrows=1)
所以基本上我想为剩余的 72 个网格单元中的每一个提供 12 个月的平均值。