Description Usage Arguments Details Value Examples
View source: R/pat_aggregate.R
Aggregate PurpleAir timeseries (pat) object along its
datetime axis. Temporal aggregation involves splitting a pat object into
separate bins along its datetime axis. FUN
is mapped to the pat
numeric variables in each bin, which are then recombined into an aggregated
pat object containing the same metadata as the incoming pat
.
1 2 3 4 5 6 | pat_aggregate(
pat,
FUN = function(x) { mean(x, na.rm = TRUE) },
unit = "minutes",
count = 60
)
|
pat |
PurpleAir Timeseries pat object. |
FUN |
The function to be applied to each vector of numeric |
unit |
Character string specifying temporal units for binning. |
count |
Number of units per bin. |
FUN
must operate on univariate numeric vectors and return a
scalar value. Besides the data variable, no additional arguments will be
provided to this function. This means that functions like mean
and
max
will need to be wrapped in a function that specifies
na.rm = TRUE
. See the examples below.
Returns an aggregated pat object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | library(AirSensor)
# Single day subset
pat <-
example_pat %>%
pat_filterDate(20180813, 20180814)
# Create aggregation functions
FUN_mean <- function(x) mean(x, na.rm = TRUE)
FUN_max <- function(x) max(x, na.rm = TRUE)
FUN_count <- function(x) length(na.omit(x))
# Hourly means
pat %>%
pat_aggregate(FUN_mean) %>%
pat_extractData() %>%
dplyr::select(1:9)
# Hourly maxes
pat %>%
pat_aggregate(FUN_max) %>%
pat_extractData() %>%
dplyr::select(1:9)
# Hourly counts
pat %>%
pat_aggregate(FUN_count) %>%
pat_extractData() %>%
dplyr::select(1:9)
# Alternative 10 minute aggregation (advanced users only - see details.)
pat %>%
pat_aggregate(FUN_max, unit = "minutes", count = 10) %>%
pat_extractData() %>%
dplyr::select(1:9) %>%
dplyr::slice(1:6)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.