1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
\name{subset}
\alias{subset}
\alias{subset,Raster-method}
\alias{subset,RasterStack-method}
\title{Subset layers in a Raster* object}
\description{
Extract a set of layers from a RasterStack or RasterBrick object.
}
\usage{
\S4method{subset}{Raster}(x, subset, drop=TRUE, filename='', ...)
\S4method{subset}{RasterStack}(x, subset, drop=TRUE, filename='', ...)
}
\arguments{
\item{x}{RasterBrick or RasterStack object}
\item{subset}{integer or character. Should indicate the layers (represented as integer or by their name)}
\item{drop}{If \code{TRUE}, a selection of a single layer will be returned as a RasterLayer}
\item{filename}{character. Output filename (optional)}
\item{...}{additional arguments as for \code{\link{writeRaster}}}
}
\value{
Raster* object
}
\seealso{ \code{\link[raster:addLayer]{dropLayer}}}
\examples{
s <- stack(system.file("external/rlogo.grd", package="raster"))
sel <- subset(s, 2:3)
# Note that this is equivalent to
sel2 <- s[[2:3]]
# and in this particular case:
sel3 <- dropLayer(s, 1)
nlayers(s)
nlayers(sel)
# effect of 'drop=FALSE' when selecting a single layer
sel <- subset(s, 2)
class(sel)
sel <- subset(s, 2, drop=FALSE)
class(sel)
}
\keyword{ spatial }
|