step_difftime | R Documentation |
step_difftime()
creates a specification of a recipe step that will
calculate difftimes of the data.
step_difftime(
recipe,
...,
role = NA,
trained = FALSE,
time = NULL,
tz = NULL,
unit = "auto",
columns = NULL,
skip = FALSE,
id = rand_id("difftime")
)
recipe |
A recipe object. The step will be added to the sequence of operations for this recipe. |
... |
One or more selector functions to choose which
variables are affected by the step. See |
role |
Not used by this step since no new variables are created. |
trained |
A logical to indicate if the quantities for preprocessing have been estimated. |
time |
date-time or date objects. Used for reference. Must match the type of variable. |
tz |
an optional time zone specification to be used for the conversion, mainly for "POSIXlt" objects. |
unit |
character string. Units in which the results are desired. Must be one of "auto", "secs", "mins", "hours","days", and "weeks" Defaults to "auto". |
columns |
A character string of variable names that will
be populated (eventually) by the |
skip |
A logical. Should the step be skipped when the
recipe is baked by |
id |
A character string that is unique to this step to identify it. |
An updated version of recipe
with the new step
added to the sequence of existing steps (if any). For the
tidy
method, a tibble with columns terms
(the
columns that will be affected) and base
.
library(recipes)
example_date <- data.frame(
dates = seq(as.Date("2010/1/1"), as.Date("2016/1/1"), by = "quarter")
)
example_datetime <- data.frame(
datetimes = seq(ISOdate(1993,1,1), ISOdate(1993,1,2), by = "hour")
)
rec <- recipe(~ dates, data = example_date) %>%
step_difftime(dates, time = as.Date("2010/1/1"))
difftime_obj <- prep(rec)
bake(difftime_obj, new_data = NULL)
recipe(~ dates, data = example_date) %>%
step_difftime(dates, time = as.Date("2010/1/1"), unit = "weeks") %>%
prep() %>%
bake(new_data = NULL)
recipe(~ datetimes, data = example_datetime) %>%
step_difftime(datetimes, time = ISOdate(1993,1,1), unit = "secs") %>%
prep() %>%
bake(new_data = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.