在 R 中从多个光栅文件创建最大光栅

In R create maximum raster from mulitple raster files

我是 R 的新手,所以这可能是个愚蠢的问题,但我自己也弄不明白。

这是我的问题。 我有多个具有相同网格大小并覆盖相同区域的 asc 文件。我想从所有 asc 文件中获取每个网格的最大值。 我尝试了多种方法:

   for (i in 1:144){
    asc0<-rasterToPoints(raster(asc0))
        asc1<-rasterToPoints(raster(asc[i]))
        asc0[,3] <-pmax(asc0[,3], asc1[,3])
    }

当我循环抛出文件时,这个失败了,因为它遗漏了 NA,所以我的 asc0(我的基本文件)与我的下一个文件 asc1[2] 的大小不同。

有人知道这个方法吗?我已经准备好循环遍历所有文件,有 13x144 文件。 但是我想不出一种方法来获取最大值、存储它并将其与下一个文件进行比较。

谢谢,非常感谢您的帮助!!!

使用stackmax:

r1 <- r2 <- r3 <- raster(nrows=10, ncols=10, xmn=0, xmx=10, ymn=0, ymx=10)
r1[] <- 1   # raster with 1
r2[] <- 2   # raster with 2
r3[] <- 3   # raster with 3
s1 <- stack(r1, r2, r3)
s1
#class       : RasterStack 
#dimensions  : 10, 10, 100, 3  (nrow, ncol, ncell, nlayers)
#resolution  : 1, 1  (x, y)
#extent      : 0, 10, 0, 10  (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
#names       : layer.1, layer.2, layer.3 
#min values  :       1,       2,       3    <- values between 1 and 3
#max values  :       1,       2,       3    <- values between 1 and 3

max(s1)
#class       : RasterLayer 
#dimensions  : 10, 10, 100  (nrow, ncol, ncell)
#resolution  : 1, 1  (x, y)
#extent      : 0, 10, 0, 10  (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
#data source : in memory
#names       : layer 
#values      : 3, 3  (min, max)   <- 3 only