Learn R Programming

MazamaTimeSeries (version 0.3.0)

mts_summarize: Create summary time series for an mts time series object

Description

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.

Usage

mts_summarize(
  mts,
  timezone = NULL,
  unit = c("day", "week", "month", "year"),
  FUN = NULL,
  ...,
  minCount = NULL
)

Value

An mts time series object containing daily (or other) statistical summaries. (A list with meta and data dataframes.)

Arguments

mts

mts object.

timezone

Olson timezone used to interpret dates.

unit

Unit used to summarize by (e.g. "day").

FUN

Function used to summarize time series.

...

Additional arguments to be passed to FUN (_e.g._ na.rm = TRUE).

minCount

Minimum number of valid data records required to calculate summaries. Time periods with fewer valid records will be assigned NA.

Examples

Run this code
library(MazamaTimeSeries)

daily <-
  mts_summarize(
    mts = Carmel_Valley,
    timezone = NULL,
    unit = "day",
    FUN = mean,
    na.rm = TRUE,
    minCount = 18
  )

# Daily means
head(daily$data)

Run the code above in your browser using DataLab