Applies a dplyr filtering expression inside a time-based period (window).
filter_by_time() for filtering continuous ranges defined by start/end dates.
filter_period() enables filtering expressions like:
Filtering to the maximum value each month.
Filtering the first date each month.
Filtering all rows with value greater than a monthly average
filter_period(.data, ..., .date_var, .period = "1 day")
Filtering expression. Expressions that return a logical value, and are defined in terms of the variables in .data. If multiple expressions are included, they are combined with the & operator. Only rows for which all conditions evaluate to TRUE are kept.
A column containing date or date-time values. If missing, attempts to auto-detect date column.
A period to filter within.
Time units are grouped using
The value can be:
Arbitrary unique English abbreviations as in the
Time-Based dplyr functions:
summarise_by_time() - Easily summarise using a date column.
mutate_by_time() - Simplifies applying mutations by time windows.
pad_by_time() - Insert time series rows with regularly spaced timestamps
filter_by_time() - Quickly filter using date ranges.
filter_period() - Apply filtering expressions inside periods (windows)
slice_period() - Apply slice inside periods (windows)
condense_period() - Convert to a different periodicity
between_time() - Range detection for date or date-time sequences.
slidify() - Turn any function into a sliding (rolling) function
# Libraries library(timetk) library(dplyr) # Max value in each month m4_daily %>% group_by(id) %>% filter_period(.period = "1 month", value == max(value)) # First date each month m4_daily %>% group_by(id) %>% filter_period(.period = "1 month", date == first(date)) # All observations that are greater than a monthly average m4_daily %>% group_by(id) %>% filter_period(.period = "1 month", value > mean(value))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.