Poniższy przykład pokazuje dwa sposoby uzyskania maksymalnej wartości rastra na stosie. Pierwszy wykorzystuje, max()który daje również wiele innych przydatnych informacji. Druga metoda wykorzystuje maxValue(), która daje tylko maksymalną wartość obu rastrów w stosie
library(raster)
# Generate some georeferenced raster data
x = matrix(rnorm(400),20,20)
rast = raster(x)
extent(rast) = c(36,37,-3,-2)
projection(rast) = CRS("+proj=longlat +datum=WGS84")
y = matrix(rnorm(400),20,20)
rast2 = raster(y)
extent(rast2) = c(36,37,-3,-2)
projection(rast2) = CRS("+proj=longlat +datum=WGS84")
raster = stack(rast, rast2)
# Now run the statistics
max(raster) # Provides min, max and additional details # Example 1
maxValue(raster) # Gives both values # Example 2...
maxValue(raster)[[1]] # Gives first in stack max value
maxValue(raster)[[2]] # Gives second in stack max value
> maxValue(raster) # Gives both values
[1] 2.688376 2.971443
> maxValue(raster)[[1]] # Gives first in stack max value
[1] 2.688376
> maxValue(raster)[[2]] # Gives second in stack max value
[1] 2.971443
>
> max(raster) # Provides min, max and additional details
class : RasterLayer
dimensions : 20, 20, 400 (nrow, ncol, ncell)
resolution : 0.05, 0.05 (x, y)
extent : 36, 37, -3, -2 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : layer
values : -1.457908, 2.971443 (min, max)
maxValueprawidłowego sposobu. Według strony pomocy lepiej użyć dodatkowego argumentu... Additional argument: layer number (for RasterStack or RasterBrick objects)