View source: R/ts-compare-data.R
ts_compare_data | R Documentation |
Given a tibble/data.frame, you can get date from two different but comparative date ranges. Lets say you want to compare visits in one year to visits from 2 years before without also seeing the previous 1 year. You can do that with this function.
ts_compare_data(.data, .date_col, .start_date, .end_date, .periods_back)
.data |
The date.frame/tibble that holds the data |
.date_col |
The column with the date value |
.start_date |
The start of the period you want to analyze |
.end_date |
The end of the period you want to analyze |
.periods_back |
How long ago do you want to compare data too. Time units
are collapsed using
Arbitrary unique English abbreviations as in the |
Uses the timetk::filter_by_time()
function in order to filter the date
column.
Uses the timetk::subtract_time()
function to subtract time from the start date.
A tibble.
Steven P. Sanderson II, MPH
Other Time_Filtering:
ts_time_event_analysis_tbl()
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(timetk))
data_tbl <- ts_to_tbl(AirPassengers) %>%
select(-index)
ts_compare_data(
.data = data_tbl
, .date_col = date_col
, .start_date = "1955-01-01"
, .end_date = "1955-12-31"
, .periods_back = "2 years"
) %>%
summarise_by_time(
.date_var = date_col
, .by = "year"
, visits = sum(value)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.