
wqData
is a constructor for the "WqData"
class that is often more convenient to use than new
. It converts a data.frame containing water quality data in “long” or “wide” format to a "WqData"
object. In “long” format, observations are all in one column and a second column is used to designate the variable being observed. In “wide” format, observations for each variable are in a separate column.
wqData(data, locus, wqdata, site.order, time.format = "%Y-%m-%d", type = c("long", "wide"))
data
that correspond to time
, site
and depth
.
data
that correspond to variable
and value
. In the case of “wide” data, character or numeric vector designating column names or numbers, respectively, in data
that denote water quality variable data.
TRUE
, site
factor levels will be ordered in alphanumeric order.
time
defined by ISO C/POSIX standard (see strptime
).
data
.
"WqData"
.
melt
the data. The function also removes NA
observations, converts site
to (possibly ordered) factors with valid variable names, and converts time
to class "Date"
or "POSIXct"
and ISO 8601 format, depending on time.format
. as.Date
, strptime
, WqData-class
# Create new WqData object from sfbay data. First combine date and time
# into a single string after making sure that all times have 4 digits.
sfb <- within(sfbay, time <- substring(10000 + time, 2, 5))
sfb <- within(sfb, time <- paste(date, time, sep = ' '))
sfb <- wqData(sfb, 2:4, 5:12, site.order = TRUE, type = "wide",
time.format = "%m/%d/%Y %H%M")
head(sfb)
tail(sfb)
# If time of day were not required, then the following would suffice:
sfb <- wqData(sfbay, c(1,3,4), 5:12, site.order = TRUE, type = "wide",
time.format = "%m/%d/%Y")
Run the code above in your browser using DataLab