condense_period {timetk} | R Documentation |
Convert the Period to a Lower Periodicity (e.g. Go from Daily to Monthly)
Description
Convert a data.frame
object from daily to monthly,
from minute data to hourly, and more. This allows the user to easily
aggregate data to a less granular level by taking the value from either
the beginning or end of the period.
Usage
condense_period(.data, .date_var, .period = "1 day", .side = c("start", "end"))
Arguments
.data |
A |
.date_var |
A column containing date or date-time values. If missing, attempts to auto-detect date column. |
.period |
A period to condense the time series to.
Time units are condensed using The value can be:
Arbitrary unique English abbreviations as in the
|
.side |
One of "start" or "end". Determines if the first observation in the period should be returned or the last. |
Value
A tibble
or data.frame
See Also
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
Examples
# Libraries
library(dplyr)
# First value in each month
m4_daily %>%
group_by(id) %>%
condense_period(.period = "1 month")
# Last value in each month
m4_daily %>%
group_by(id) %>%
condense_period(.period = "1 month", .side = "end")