trim: Trim

Description Usage Arguments Value Author(s) Examples

Description

Trim (shrink) a Raster* object by removing outer rows and columns that all have the same value (e.g. NA).

Or remove the whitespace before or after a string of characters (or a matrix, or the character values in a data.frame).

Usage

1
2
3
4
## S4 method for signature 'Raster'
trim(x, padding=0, values=NA, filename='', ...)
## S4 method for signature 'character'
trim(x, internal=FALSE, ...)

Arguments

x

Raster* object or a character string

values

numeric. Value(s) based on which a Raster* should be trimmed

padding

integer. Number of outer rows/columns to keep

filename

character. Optional output filename

internal

logical. If TRUE, sequential internal spaces are replaced by a single space

...

If x is a Raster* object: additional arguments as for writeRaster

Value

A RasterLayer or RasterBrick object (if x is a Raster* object) or a character string (if x is a character string).

Author(s)

Robert J. Hijmans and Jacob van Etten

Examples

1
2
3
4
5
6
7
8
r <- raster(ncol=18,nrow=18)
r[39:49] <- 1
r[113:155] <- 2
r[200] <- 6
s <- trim(r) 


trim("    hi folks    !   ")

Example output

Loading required package: sp
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
[1] "hi folks    !"

raster documentation built on Jan. 5, 2021, 3:01 a.m.