step_date_nearest | R Documentation |
step_date_nearest()
creates a specification of a recipe step that will
create new columns indicating the time to nearest recurrent event.
step_date_nearest(
recipe,
...,
role = "predictor",
trained = FALSE,
rules = list(),
transform = "identity",
columns = NULL,
skip = FALSE,
id = rand_id("date_nearest")
)
recipe |
A recipe object. The step will be added to the sequence of operations for this recipe. |
... |
One or more selector functions to choose variables
for this 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. |
rules |
Named list of |
transform |
A function or character indication a function used oon the resulting variables. See details for allowed names and their functions. |
columns |
A character string of variables that will be
used as inputs. This field is a placeholder and will be
populated once |
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. |
The transform
argument can be function that takes a numeric vector and
returns a numeric vector of the same length. It can also be a character
vector, below is the supported vector names. Some functions come with offset
to avoid Inf
.
"identity" function(x) x "inverse" function(x) 1 / (x + 0.5) "exp" function(x) exp(x) "log" function(x) log(x + 0.5)
The effect of transform
is illustrated below.
The naming of the resulting variables will be on the form
{variable name}_nearest_{name of rule}
An updated version of recipe
with the new check added to the
sequence of any existing operations.
library(recipes)
library(extrasteps)
library(almanac)
library(modeldata)
data(Chicago)
on_easter <- yearly() %>% recur_on_easter()
on_weekend <- weekly() %>% recur_on_weekends()
rules <- list(easter = on_easter, weekend = on_weekend)
rec_spec <- recipe(ridership ~ date, data = Chicago) %>%
step_date_nearest(date, rules = rules)
rec_spec_preped <- prep(rec_spec)
bake(rec_spec_preped, new_data = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.