monitor_collapse {AirMonitor}R Documentation

Collapse an mts_monitor object into a single time series

Description

Collapses data from all time series in a mts_monitor into a single-time series mts_monitor 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 parameters are specified.

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

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

Usage

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

Arguments

monitor

mts_monitor 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

A mts_monitor 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(AirMonitor)

# Lane County, Oregon AQSIDs all begin with "41039"
LaneCounty <-
  NW_Megafires %>%
  monitor_filter(stringr::str_detect(AQSID, '^41039')) %>%
  monitor_filterDate(20150821, 20150828)

# Get min/max for all monitors
LaneCounty_min <- monitor_collapse(LaneCounty, deviceID = 'LaneCounty_min', FUN = min)
LaneCounty_max <- monitor_collapse(LaneCounty, deviceID = 'LaneCounty_max', FUN = max)

# Create plot
monitor_timeseriesPlot(
  LaneCounty,
  shadedNight = TRUE,
  main = "Lane County Range of PM2.5 Values"
)

# Add min/max lines
monitor_timeseriesPlot(LaneCounty_max, col = 'red', type = 's', add = TRUE)
monitor_timeseriesPlot(LaneCounty_min, col = 'blue', type = 's', add = TRUE)

[Package AirMonitor version 0.4.0 Index]