step_locfimpute: Last Observation Carried Forward Imputation

View source: R/step_locfimpute.R

step_locfimputeR Documentation

Last Observation Carried Forward Imputation

Description

step_locfimpute creates a *specification* of a recipe step that will substitute missing values with the most recent variable value. If the first variable value is missing, it is imputed with the first present value.

Usage

step_locfimpute(
  recipe,
  ...,
  role = NA,
  trained = FALSE,
  skip = FALSE,
  id = rand_id("bagimpute")
)

## S3 method for class 'step_locfimpute'
tidy(x, ...)

Arguments

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 will be imputed. See [selections()] for more details. For the 'tidy' method, these are not currently used.

role

Not used by this step since no new variables are created.

trained

A logical to indicate if the number of NA values have been counted in preprocessing.

skip

A logical. Should the step be skipped when the recipe is baked?

id

a unique step id that will be used to unprep

x

A 'step_locfimpute' object.

Value

For step_locfimpute, 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 selectors or variables selected) and trained (a logical that states whether the recipe has been prepped).

Examples

library(recipes)

prepped <-
  recipe(formula = "~.", pima_diabetes) %>%
  step_locfimpute(weight_class, insulin, skinfold, diastolic_bp) %>%
  prep()

bake(prepped, new_data = pima_diabetes)

healthcareai documentation built on Sept. 5, 2022, 5:12 p.m.