我下载了worlclim/生物气候数据,它有16层。其中1-11层是温度数据。Rests是降水量数据。当我检查文档时,我应该用不同的换算系数来换算温度数据的单位。1-2,4-11层应除以10以换算成酒度,3-4层应除以100。为此,我编写了以下代码:
temp1<-clim[[1:2]]/10
temp2 <-clim[[5:11]]/10
temp3<-clim[[3:4]]/100
Stack them back according to the same order as they were in original data:
clim <-stack(temp1,temp3,temp2)我的问题是如何在不同的层上计算不同的公式,并将它们堆叠回原来的顺序?我想知道完成这些步骤的另一种方法。
谢谢!
发布于 2019-01-26 01:28:17
简单的方法可以是定义一个“划分因子”的向量,然后简单地用这个向量来划分堆栈。这样,您就不需要按“原始”顺序排列频段了:
library(raster)
a <- raster::raster(ncols = 10, nrows = 10)
a <- raster::init(a, runif)
# create a stack
b <- raster::stack(a,a,a,a,a,a)
# define vector of dividing factors
divs <- c(1,1,10,10,100,100)
# compute
c <- b / divs
c
class : RasterBrick
dimensions : 10, 10, 100, 6 (nrow, ncol, ncell, nlayers)
resolution : 36, 18 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : layer.1, layer.2, layer.3, layer.4, layer.5, layer.6
min values : 5.919103e-03, 5.919103e-03, 5.919103e-04, 5.919103e-04, 5.919103e-05, 5.919103e-05
max values : 0.99532098, 0.99532098, 0.09953210, 0.09953210, 0.00995321, 0.00995321 https://stackoverflow.com/questions/54369207
复制相似问题