timeAverage(mydata, avg.time = "day", data.thresh = 0, statistic = "mean",
percentile = NA, start.date = NA, end.date = NA, interval = NA,
vector.ws = FALSE, fill = FALSE, ...)
date
field . Can be
class POSIXct
or Date
.statistic = "percentile"
. The default is 95.POSIXct
and will
remove any non-numeric columns except a column "site".timeAverage
data.thresh
it
is necessary for timeAverage
to know what the original time
interval of the input time series is. The function will try and
calculate this interval based on the most common time gap (and
will print the assumed time gap to the screen). This works fine
most of the time but there are occasions where it may not
e.g. when very few data exist in a data frame or the data are
monthly (i.e. non-regular time interval between months). In this
case the user can explicitly specify the interval through
interval
in the same format as avg.time
e.g. interval = "month"
. It may also be useful to set
start.date
and end.date
if the time series do not
span the entire period of interest. For example, if a time series
ended in October and annual means are required, setting
end.date
to the end of the year will ensure that the whole
period is covered and that data.thresh
is correctly
calculated. The same also goes for a time series that starts later
in the year where start.date
should be set to the beginning
of the year.
timeAverage
should be useful in many circumstances where it
is necessary to work with different time average data. For
example, hourly air pollution data and 15-minute meteorological
data. To merge the two data sets timeAverage
can be used to
make the meteorological data 1-hour means first. Alternatively,
timeAverage
can be used to expand the hourly data to 15
minute data - see example below.
For the research community timeAverage
should be useful for
dealing with outputs from instruments where there are a range of
time periods used.
It is also very useful for plotting data using
timePlot
. Often the data are too dense to see
patterns and setting different averaging periods easily helps with
interpretation.timePlot
that plots time series data and uses
timeAverage
to aggregate data where necessary.## daily average values
daily <- timeAverage(mydata, avg.time = "day")
## daily average values ensuring at least 75 \% data capture
## i.e. at least 18 valid hours
daily <- timeAverage(mydata, avg.time = "day", data.thresh = 75)
## 2-weekly averages
fortnight <- timeAverage(mydata, avg.time = "2 week")
## make a 15-minute time series from an hourly one
min15 <- timeAverage(mydata, avg.time = "15 min", fill = TRUE)
Run the code above in your browser using DataLab