Learn R Programming

SpatioTemporal (version 1.1.7)

stCheckCovars: Check a data.frame of Covariates

Description

Checks that data.frame of covariates is valid, making sure that all locations specified in ID.unique exist. The function will attempt to name each row in covars using 1) covars$ID, 2) rownames(covars), and 3) as.character(1:dim(covars)[1]). The field covars$ID is added if missing and rownames are removed.

Usage

stCheckCovars(covars, ID.unique = character(0))

Arguments

covars

data.frame containing covariates, to be checked.

ID.unique

vector with unique IDs that HAVE to be present in the covariates, typically the observation locations.

Value

Updated covars data.frame.

See Also

Other object checking utilities: stCheckClass, stCheckFields, stCheckObs, stCheckSTcovars

Examples

Run this code
# NOT RUN {
##load data
  data(mesa.model)

  ##check covariates
  tmp <- stCheckCovars( mesa.model$locations, mesa.model$locations$ID )
  str(tmp)
  ##require non-existant site
  try( stCheckCovars( mesa.model$locations, "Bad.Site" ) )
  ##drop the ID
  mesa.model$locations$ID <- NULL
  tmp <- stCheckCovars( mesa.model$locations )
  ##ID:s infered from rownames (1-25)
  str(tmp)
# }

Run the code above in your browser using DataLab