clamp: Clamp values

Description Usage Arguments Value See Also Examples

Description

Clamp values to a minimum and maximum value. That is, all values below the lower clamp value and above the upper clamp value become NA (or the lower/upper value if useValue=TRUE)

Usage

1
2
3
4
## S4 method for signature 'Raster'
clamp(x, lower=-Inf, upper=Inf, useValues=TRUE, filename="", ...)
## S4 method for signature 'numeric'
clamp(x, lower=-Inf, upper=Inf, ...)

Arguments

x

RasterLayer, or numeric vector

lower

numeric. lowest value

upper

numeric. highest value

useValues

logical. If FALSE values outside the clamping range become NA, if TRUE, they get the extreme values

filename

character. Filename for the output RasterLayer (optional)

...

additional arguments as for writeRaster

Value

Raster object

See Also

reclassify

Examples

1
2
3
4
r <- raster(ncols=12, nrows=12)
values(r) <- 1:ncell(r)
rc <- clamp(r, 25, 75) 
rc

Example output

Loading required package: sp
class       : RasterLayer 
dimensions  : 12, 12, 144  (nrow, ncol, ncell)
resolution  : 30, 15  (x, y)
extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 
data source : in memory
names       : layer 
values      : 25, 75  (min, max)

raster documentation built on Nov. 15, 2020, 1:06 a.m.