Collapses data from all time series in mts into a single-time series mts object using the function provided in the FUN argument. The single-time series result will be located at the mean longitude and latitude unless longitude and latitude are specified.

Any columns of mts$meta that are constant across all records will be retained in the returned mts$meta.

The core metadata associated with this location (e.g. countryCode, stateCode, timezone, ...) will be determined from the most common (or average) value found in mts$meta. This will be a reasonable assumption for the vast majority of intended use cases where data from multiple devices in close proximity are averaged together.

mts_collapse(
  mts,
  longitude = NULL,
  latitude = NULL,
  deviceID = "generatedID",
  FUN = mean,
  na.rm = TRUE,
  ...
)

Arguments

mts

mts object.

longitude

Longitude of the collapsed time series.

latitude

Latitude of the collapsed time series.

deviceID

Device identifier for the collapsed time series.

FUN

Function used to collapse multiple time series.

na.rm

Logical specifying whether NA values should be ignored when FUN is applied.

...

additional arguments to be passed on to the apply() function.

Value

An mts time series object representing a single time series. (A list with meta and data dataframes.)

Note

After FUN is applied, values of +/-Inf and NaN are converted to NA. This is a convenience for the common case where FUN = min/max or FUN = mean and some of the time steps have all missing values. See the R documentation for min for an explanation.

Examples

library(MazamaTimeSeries)

mon <-
  mts_collapse(
    mts = example_mts,
    deviceID = "example_ID"
  )

# mon$data now only has 2 columns
names(mon$data)
#> [1] "datetime"              "9qh1b45fex_example_ID"

plot(mon$data, type = 'b', main = mon$meta$deviceID)