View source: R/timeWeightedMean.R
timeWeightedMean | R Documentation |
Computes the mean weighted by the duration between values.
timeWeightedMean(x, time, na.rm = TRUE, fill = TRUE, by.period = FALSE, excessive = 2.5)
x |
a sequnece of numeric values whose mean is to be computed. |
time |
the times associated with |
na.rm |
remove missing values before computing the mean? |
fill |
expand the weights for the first and last observation to the end of the period? Otherwise, the weight is based on the distance to the second or next-to-last observation. |
by.period |
computes wights by the periods defined by |
excessive |
a warning is issued if the largest weight for any
observation exceeds |
The values of time
are expected to be in decimal format, where the
integer part indicates the period and the fractional part linearly
distributed through the period. For example, the year 2000 begins at 2,000.0
and July 2, 2000 is 2,000.5. The function dectime
can be used to
convert Date
or POSIX
to decimal format. If time
is of
class "Date," or any "POSIX" classs, it is converted using
dectime
.
If na.rm
is FALSE
and byeriod
is
TRUE
, then missing values are returned only for periods that contain
a missing value (NA
).
If by.period
is TRUE
, then a vector with one entry per
period, otherwise the mean for the entire data set.
Crawford,C.G., 2004, Sampling strategies for estimating acute and chronic exposures of pesticides in streams: Journal of the American Water Resources Association, v. 40, n. 2, p 485-502.
weighted.mean
, dectime
## Not run: library(smwrData) data(QW05078470) with(QW05078470, timeWeightedMean(P00665, dectime(DATES))) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.