Description Usage Arguments Details Value Examples
View source: R/patData_aggregate.R
Aggregate a dataframe into temporal bins and apply a function.
Temporal aggregation involves splitting a dataframe into separate bins along
its datetime
axis. FUN
is mapped to the df
dataframe records in each bin which are then recombined into an aggregated
dataframe.
1 2 3 4 5 6 |
df |
Timeseries pat data, or timeseries data.frame with valid datetime column. |
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. |
This function is intended for advanced users who wish to have more
flexibility than the standard pat_aggregate() while aggregating
timeseries data. FUN
can operate and access all numeric vectors
within the data frame df
and must return a matrix or tibble of numeric
values. Any errors generated during application of FUN
on subsets
of df
must be handled as in the example.
Returns an aggregated data.frame 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 | library(AirSensor)
# Single day subset
pat <-
example_pat %>%
pat_filterDate(20180813, 20180814)
# Two Sample Student T-Test (advanced users only - see details.)
FUN_ttest <- function(x) {
result <- try({
hourly_ttest <- stats::t.test(x$pm25_A, x$pm25_B, paired = FALSE)
tbl <- dplyr::tibble(
t_score = as.numeric(hourly_ttest$statistic),
p_value = as.numeric(hourly_ttest$p.value),
df_value = as.numeric(hourly_ttest$parameter)
)
}, silent = TRUE)
if ( "try-error" %in% class(result) ) {
tbl <- dplyr::tibble(
t_score = as.numeric(NA),
p_value = as.numeric(NA),
df_value = as.numeric(NA)
)
}
return(tbl)
}
t.testStats <-
pat %>%
pat_extractData() %>% # Note: Extract the timeseries data.frame
patData_aggregate(FUN_ttest)
head(t.testStats)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.