Learn R Programming

wq (version 0.3-3)

tsMake: Create time series from water quality data

Description

Creates a matrix time series object from an object of class "WqData", either all variables for a single site or all sites for a single variable.

Usage

## S3 method for class 'WqData':
tsMake(object, focus, layer,
    type = c("ts.mon", "zoo"), qprob = NULL)

Arguments

Value

A matrix of class "mts" or "zoo".

Rdversion

1.1

Details

When qprob = NULL, the function averages all included depths for each day, the implicit assumption being that the layer is well-mixed and/or the samples are evenly distributed with depth in the layer. If layer = "max.depths", then only the value at the maximum depth for each time, site and variable combination will be used (this can take a relatively long time). The function produces a matrix time series of all variables for the specified site or all sites for the specified variable. If no layer is specified, all depths will be used. If type = "ts.mon", available daily data are averaged to produce a monthly time series, from which a quarterly or annual series can be created if needed. If you want values for the actual dates of observation, then set type = "zoo".

When qprob is a number from 0 to 1, it is interpreted as a probability and the corresponding quantile is used to aggregate observations within the specified layer. So to get the maximum, for example, use qprob = 1. If type = "ts.mon", the same quantile is used to aggregate all the available daily values.

See Also

WqData-class

Examples

Run this code
# Create new WqData object
sfb <- wqData(sfbay, c(1, 3:4), 5:12, site.order = TRUE,
         time.format = "%m/%d/%Y", type = "wide")

# Find means in the 0-10 m layer
y <- tsMake(sfb, focus = 's27', layer = c(0, 10))
plot(y, main = 'Station 27')
# Or select medians in the same layer
y1 <- tsMake(sfb, focus = 's27', layer = c(0, 10), qprob = 0.5)
plot(y1, main = 'Station 27')
# Compare means:medians
apply(y/y1, 2, mean, na.rm=TRUE)

# Combine a layer with a single additional depth
y <- tsMake(sfb, focus = 'chl', layer = list(c(0, 2), 5))
plot(y, main = 'Chlorophyll a, ug/L')

# Use values from the deepest samples
y <- tsMake(sfb, focus = 'dox', layer = "max.depths", type = 'zoo')
head(y)
plot(y, type="h", main = "'Bottom' DO, mg/L")

Run the code above in your browser using DataLab