View source: R/scale_to_date.R
scale_to_date | R Documentation |
Pick a date and provide some variables. Those variables will be adjusted to be relative to their value on that date. Usually used to calculate foot traffic growth relative to a certain date.
scale_to_date( data, adj_vars, date, date_var = "date", by = NULL, growth = TRUE, format_percent = FALSE, accuracy = 0.1 )
data |
Any type of data set that can be coerced to a |
adj_vars |
Character vector of the variable names you'd like adjusted to be relative to the date. |
date |
The date you'd like everything relative to, as a date object. |
date_var |
The name of the date variable, as a string. |
by |
Character vector of the variable names you'd like the operation to be performed by. There should only be one observation for which |
growth |
Set to |
format_percent |
Set to |
accuracy |
If |
# Create some data to scale relative to patterns <- data.table(date = c(lubridate::ymd('2020-01-15'), lubridate::ymd('2020-01-16'), lubridate::ymd('2020-01-17')), visits_by_day = c(1,2,3)) # Make everything relative to January 15! scale_to_date(patterns, 'visits_by_day', lubridate::ymd('2020-01-15'))[]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.