View source: R/step_epi_slide.R
step_epi_slide | R Documentation |
step_epi_slide()
creates a specification of a recipe step
that will generate one or more new columns of derived data by "sliding"
a computation along existing data.
step_epi_slide(
recipe,
...,
.f,
.window_size = NULL,
.align = c("right", "center", "left"),
role = "predictor",
prefix = "epi_slide_",
f_name = clean_f_name(.f),
skip = FALSE,
id = rand_id("epi_slide")
)
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 |
.f |
A function in one of the following formats:
Note that in cases 3 and 4, |
.window_size |
the size of the sliding window, required. Usually a
non-negative integer will suffice (e.g. for data indexed by date, but more
restrictive in other time_type cases (see |
.align |
a character string indicating how the window should be aligned.
By default, this is "right", meaning the slide_window will be anchored with
its right end point on the reference date. (see |
role |
For model terms created by this step, what analysis role should
they be assigned? |
prefix |
A character string that will be prefixed to the new column. |
f_name |
a character string of at most 20 characters that describes the
function. This will be combined with |
skip |
A logical. Should the step be skipped when the
recipe is baked by |
id |
A unique identifier for the step |
An updated version of recipe
with the new step added to the
sequence of any existing operations.
jhu <- covid_case_death_rates %>%
filter(time_value >= as.Date("2021-01-01"), geo_value %in% c("ca", "ny"))
rec <- epi_recipe(jhu) %>%
step_epi_slide(case_rate, death_rate,
.f = \(x) mean(x, na.rm = TRUE),
.window_size = 7L
)
bake(prep(rec, jhu), new_data = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.