Learn R Programming

raster (version 1.9-27)

focal_old: Focal (old functions)

Description

These functions are depracated. They have been replaced by the new focal function (with slightly different arguments). focal_old was named focal in previous versions and is still included to compare with and transition to the new function. Calculate values for the neighborhood of focal cells. focalNA keeps original values except where these are NA. New values are computed with function fun, using the values of the cells in the neigborhood of a focal cell (including the focal cell).

Usage

focal_old(x, ngb=3, fun=mean, na.rm=TRUE, filename="", ...) 
focalNA(x, ngb=3, fun=mean, recursive=FALSE, maxrec=0, filename="", ...)

Arguments

x
A RasterLayer object
ngb
Neighborhood size. A neighborhood is expressed in number of cells in a single direction or in two direction from the focal cell. I.e. ngb=3 refers to 2 cells at each side of the focal cell, queen's case, 9 cells in total. This is equivalent
fun
The function to be applied. The function fun should take multiple numbers, and return a single number. For example mean, modal, min or max. It should also accept a na.rm argument (or ignore it, e.g. as one of the 'dots' arguments. For example, lengt
na.rm
Logical. If TRUE, NA will be removed from focal computations. The result will only be NA if all focal cells are NA
recursive
Logical. If TRUE, the function will continue recursively untill there are no more cells with NA
maxrec
Integer. Maximum number of recursions (if recursive=TRUE)
filename
Output filename for a new raster
...
additional arguments. See Details.

Value

  • RasterLayer

Details

The following additional arguments can be passed, to replace default values for this function rll{ overwrite Logical. If TRUE, "filename" will be overwritten if it exists format Character. Output file type. See writeRaster datatype Character. Output data type. See dataType progress Character. "text", "window", or "" (the default, no progress bar) }

See Also

focal

Examples

Run this code
r <- raster(ncols=36, nrows=18)
r[] <- runif(ncell(r)) 
rf <- focal_old(r, fun=mean, ngb=3)

Run the code above in your browser using DataLab