Learn R Programming

chronosphere (version 0.4.1)

subset,XArray-method: Subset a RasterArray or SpatialArray object

Description

Extract subsets of RasterArray or SpatialArray class object similarly to a regular array.

Usage

# S4 method for XArray
subset(x, i, j, ..., oneDim = FALSE, drop = TRUE)

Value

A RasterLayer, RasterArray, Spatial* or SpatialArray class object.

Arguments

x

RasterArray or SpatialArray object.

i

subscript of the first dimension(rows) or vector-like subsetting.

j

subscript of the second dimension (columns).

...

subscript of additional dimensions.

oneDim

logical In case of multidimensional RasterArrays or SpatialArrays, setting oneDim to TRUE allows the application of one dimensional subscripts.

drop

logical in case the result of subsetting is a single element, should the \codeRasterArray or SpatialArray wrapper be dropped and the element be reduced to a single RasterLayer/ Spatial* object?

Examples

Run this code
data(dems)
# first 4
subset(dems, i=1:4)
# missing at the end
subset(dems, i=1:12)
# character subscript
subset(dems, i=c("5", "25"))
# logical subscript
subs <- rep(TRUE, length(dems))
subs[1] <- FALSE # remove first
subset(dems, i= subs)
# no drop
subset(dems, i=1, drop=FALSE)
data(coasts)
subset(coasts, i=2, j=1:2)

Run the code above in your browser using DataLab