Skip to content

step_naomit() creates a specification of a recipe step that will remove observations (rows of data) if they contain NA or NaN values.

Usage

step_naomit(
  recipe,
  ...,
  role = NA,
  trained = FALSE,
  columns = NULL,
  skip = TRUE,
  id = rand_id("naomit")
)

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 variables for this step. See selections() for more details.

role

Unused, include for consistency with other steps.

trained

A logical to indicate if the quantities for preprocessing have been estimated. Again included for consistency.

columns

A character string of the selected variable names. This field is a placeholder and will be populated once prep() is used.

skip

A logical. Should the step be skipped when the recipe is baked by bake()? While all operations are baked when prep() is run, some operations may not be able to be conducted on new data (e.g. processing the outcome variable(s)). Care should be taken when using skip = FALSE.

id

A character string that is unique to this step to identify it.

Value

An updated version of recipe with the new step added to the sequence of any existing operations.

Row Filtering

This step can entirely remove observations (rows of data), which can have unintended and/or problematic consequences when applying the step to new data later via bake(). Consider whether skip = TRUE or skip = FALSE is more appropriate in any given use case. In most instances that affect the rows of the data being predicted, this step probably should not be applied at all; instead, execute operations like this outside and before starting a preprocessing recipe().

Tidying

When you tidy() this step, a tibble is returned with columns terms and id:

terms

character, the selectors or variables selected

id

character, id of this step

Case weights

The underlying operation does not allow for case weights.

See also

Examples


recipe(Ozone ~ ., data = airquality) %>%
  step_naomit(Solar.R) %>%
  prep(airquality, verbose = FALSE) %>%
  bake(new_data = NULL)
#> # A tibble: 146 × 6
#>    Solar.R  Wind  Temp Month   Day Ozone
#>      <int> <dbl> <int> <int> <int> <int>
#>  1     190   7.4    67     5     1    41
#>  2     118   8      72     5     2    36
#>  3     149  12.6    74     5     3    12
#>  4     313  11.5    62     5     4    18
#>  5     299   8.6    65     5     7    23
#>  6      99  13.8    59     5     8    19
#>  7      19  20.1    61     5     9     8
#>  8     194   8.6    69     5    10    NA
#>  9     256   9.7    69     5    12    16
#> 10     290   9.2    66     5    13    11
#> # ℹ 136 more rows