Welcome to TERN Knowledge Base

# Raster Values: Numerical Summaries

To compute Numerical Summaries for the cells of each layer we can use:

- The 'summary' function, which calculate minimum, 1st quartile, median, 3rd quartile, maximum, and the number of cells containing missing data. Summary is a generic function; however, it invokes particular methods depending on the class of the first argument.
- The 'cellStats' function from the 'raster' package, which computes individual summary statistics (e.g. 'mean', 'sd',…).

We can also use functions in the 'base' and 'stats' packages (e.g. 'mean', 'sd',…), provided in the R installation. However, they raster need to be previously converted to values (using the 'values' function in the 'raster' package) and it would apply to the whole Raster* object. That is, this approach would work fine for a single layer raster. However, for multi-layer rasters it would return the mean (or sd,….) of the hole Raster* object, rather than for individual raster layers as 'cellStats'.

**EXAMPLES**

Below examples of the computation of numerical summaries for raster layers in R are presented. These examples are taken from the “Effects of Cyclone Yasi on Green Cover at Mission Beach” tutorial. It can be beneficial to put the code snippets in context by looking at a broader section of the R script. Code snippets have a grey background, and outputs have a white background.

**Multiple numerical summary statistics using the function ‘summary’ from the ‘base’ package**

**Individual summary statistics using the function ‘cellStats’ from the ‘raster’ package**

*RasterLayer object*

*RasterBrick object*

** **

**Individual summary statistics using statistical functions from the ‘base’ package (e.g. ‘mean’, ‘sd’)**

*RasterLayer object*

*RasterBrick object*

Applying the ‘mean’ function on a Multi-Layer Raster object summarises the values in all the layers into a single value. This behaviour is different that obtained using the ‘cellStats’ function with the argument ‘mean’, which returned a summary value for each layer (see above).

Provide your feedback about the experience with Knowledge base