Learn R Programming

SpatioTemporal (version 0.9.2)

create.data.matrix: Create a Data Matrix from a mesa.data Structure

Description

Creates a data matrix from a mesa.data structure, or from a set of vectors. Missing data are marked as NA.

Usage

create.data.matrix(mesa.data = NA, obs = mesa.data$obs$obs,
    date = mesa.data$obs$date, ID = mesa.data$obs$ID,
    subset = NA)

Arguments

mesa.data
A data structure containing the observations, see mesa.data. Use either this or the obs, date, and ID inputs.
obs
A vector of observations, see mesa.data.
date
A vector of observation times, see mesa.data.
ID
A vector of observation locations, see mesa.data.
subset
A subset of locations to extract the data matrix for. This would be a vector of strings that matches names in ID. A warning will be given for each name not found in ID.

Value

  • Returns a matrix with dimensions (number of timepoints)-by-(number of locations.) Row and column names of the matrix are taken as ID and sort(unique(date)) respectively.

encoding

latin1

See Also

Converts a mesa.data structure to a matrix, used internally by calc.smooth.trends. The data matrix can be used as input to SVD.smooth, SVD.smooth.cv, and SVD.miss. See also create.data.model.

For other data functions, see mesa.data.raw, mesa.data.model, default.LUR.list, and construct.LUR.basis.

Examples

Run this code
##load the data
data(mesa.data)

##create a data matrix
M1 <- create.data.matrix(mesa.data)
dim(M1)
head(M1)

##create data matrix for only a few locations
M2 <- create.data.matrix(mesa.data, subset =
     c("60370002","60370016","60370113","60371002",
       "60371103","60371201","L001","L002"))
dim(M2)
head(M2)
if( (dim(M1)[1]!=dim(mesa.data$trend)[1]) ||
    (dim(M1)[2]!=dim(mesa.data$location)[1]) ){
  stop("create.data.matrix: dimension missmatch - M1")
}
if( (dim(M2)[1]!=dim(mesa.data$trend)[1]) || (dim(M2)[2]!=8) ){
  stop("create.data.matrix: dimension missmatch - M2")
}
if( max(abs(M1[,colnames(M2)]-M2),na.rm=TRUE) > 1e-10 ){
  stop("create.data.matrix: M1!=M2")
}

Run the code above in your browser using DataLab