Learn R Programming

wq (version 0.2-9)

WqData-class: Class "WqData"

Description

A simple extension or subclass of the "data.frame" class for typical discrete water quality monitoring programs that examine phenomena on a time scale of days or longer. It requires water quality data to be in a specific long format, although a generating function wqData can be used for different forms of data.

Arguments

Rdversion

1.1

docType

class

Objects from the Class

Objects can be created by calls of the form new("WqData", d), where d is a data.frame. d should have columns named time, site, depth, variable, value of class "DateTime", "factor", "numeric", "factor", "numeric", respectively.

Extends

Class "data.frame", directly. Class "list", by class "data.frame", distance 2. Class "oldClass", by class "data.frame", distance 2. Class "vector", by class "data.frame", distance 3.

See Also

DateTime-class, tsMake,WqData-method, wqData

Examples

Run this code
showClass("WqData")

### Make a WqData object from sfbay data ###

# Combine date and time into a POSIXct object called time.
# In this case, requires first making sure all sfbay times have 4
# digits. Also drop date, which is no longer needed.
sfb1 <- transform(sfbay, time = substring(10000 + time, 2, 5))
sfb1 <- transform(sfb1, time = paste(date, time, sep = ""))
sfb1 <- transform(sfb1, time = as.POSIXct(time, format = "%m/%d/%Y %H%M"))
sfb1$date <- NULL

# If time of day were not needed, then the following would suffice:
# sfb1 <- transform(sfbay, time = as.Date(date, "\%m/\%d/\%Y"))
# sfb1$date <- NULL

# 'Melt' the data into the correct format
# which automatically gives required variable and value fields.
require(reshape)
m1 <- melt(sfb1, id.vars = c('time', 'stn', 'depth'))

# Make sure names of id.vars conform to WqData requirements
names(m1)[2] <- "site"

# Make sure all column classes conform to WqData requirements
m1 <- transform(m1, 
        site = factor(paste("s", site, sep = ""), ordered = TRUE)
      )

# Remove NAs
m1 <- subset(m1, !is.na(value))
rownames(m1) <- 1:nrow(m1)

# Create the new WqData object
sfb <- new('WqData', m1)
###

# Summarize the data
summary(sfb)

# Create multi-page pdf of strip chart summary of data
pdf()  # default is to create Rplots.pdf
plot(sfb, vars = c('chl', 'dox', 'spm'))
dev.off()

Run the code above in your browser using DataLab