Individual time series in mts$data are grouped by unit and then
summarized using FUN.
The most typical use case is creating daily averages where each day begins at
midnight. This function interprets times using the mts$data$datetime
tzone attribute so be sure that is set properly.
Day boundaries are calculated using the specified timezone or, if
NULL, the most common (hopefully only!) time zone found in
mts$meta$timezone. Leaving timezone = NULL, the default,
results in "local time" date filtering which is the most common use case.
mts_summarize(
mts,
timezone = NULL,
unit = c("day", "week", "month", "year"),
FUN = NULL,
...,
minCount = NULL
)mts object.
Olson timezone used to interpret dates.
Unit used to summarize by (e.g. "day").
Function used to summarize time series.
Additional arguments to be passed to FUN
(_e.g._ na.rm = TRUE).
Minimum number of valid data records required to calculate
summaries. Time periods with fewer valid records will be assigned NA.
An mts time series object containing daily (or other)
statistical summaries.
(A list with meta and data dataframes.)
Because the returned mts object is defined on a daily axis in a
specific time zone, it is important that the incoming mts contain
timeseries associated with a single time zone.
library(MazamaTimeSeries)
daily <-
mts_summarize(
mts = Carmel_Valley,
timezone = NULL,
unit = "day",
FUN = mean,
na.rm = TRUE,
minCount = 18
)
# Daily means
head(daily$data)
#> # A tibble: 6 × 2
#> datetime a9572a904a4ed46d_840060530002
#> <dttm> <dbl>
#> 1 2016-07-22 00:00:00 2.04
#> 2 2016-07-23 00:00:00 6.96
#> 3 2016-07-24 00:00:00 12.4
#> 4 2016-07-25 00:00:00 17.2
#> 5 2016-07-26 00:00:00 64.5
#> 6 2016-07-27 00:00:00 12.8