Learn R Programming

chronosphere (version 0.4.1)

extract: Extraction of values from multiple RasterLayers in a RasterArray object

Description

The function takes a set of time-dependent coordinates and extracts the value they point to from associted RasterLayers in a RasterArray.

Usage

extract

# S4 method for RasterArray,matrix extract(x, y)

# S4 method for RasterArray,data.frame extract(x, y, by = NULL, margin = 1, lng = "plng", lat = "plat", force = NULL)

Value

A numeric

vector, matrix or array of values.

Format

An object of class standardGeneric of length 1.

Arguments

x

(RasterArray). A set of RasterLayers that are associated with entries (one dimension) or the rows of x.

y

(matrix or data.frame). The data table containing the coordinates and (optionally) the indices or names of the associated RasterLayers in x.

by

(character or vector) In case of a data.frame input, the link between x and y. If by is a character string then it is expected to be column of x and should contain the names or the indices of the associated RasterLayers in x. If it is a vector its length should match the number of rows in x and it will be used as if it were a column of x.

margin

(numeric) A single value describing which margin (dimension of x) by is referring to (1: rows, 2: columns, etc.).

lng

(character) A column of x that includes the paleolongitudes.

lat

(character) A column of x that includes the paleolatitudes.

force

(character) If set to "numeric" the by argument or the column it points to will be converted to numeric values, and x will be subsetted with numeric subscripts of the x RasterArray. If set to "character", the by column (or vector) will be forced to character values and will be used as character subscripts.

Examples

Run this code
# one pair of random coordinates from Africa
mat <- matrix(c(                
  -1.34, 42.96
), ncol=2, byrow=TRUE) 

# repeat four times
mat<- mat[rep(1,4), ]

# assign default names and age
df<- data.frame(plng=mat[, 1],plat=mat[, 2], age=c(1,3,5, 1))
rownames(df) <- paste("point", 1:nrow(df))

# first coordinate pair will be extrated from RasterLayer 1 ["0"]
# second coordinate pair will be extracted from RasterLayer 3 ["10"]
# thrid coordinate pair will be extracted from RasterLayer 5 ["20"]
# fourth coordinate pair will be extracted from RasterLayer 1 ["0"]
data(dems)
extract(dems, df, by="age")

# by=NULL will be implemented in the next update 
# (all coordinates extracted from all layers)

Run the code above in your browser using DataLab