Learn R Programming

naniar (version 0.6.0)

scoped-impute_median: Scoped variants of impute_median

Description

impute_median imputes the median for a vector. To get it to work on all variables, use impute_median_all. To only impute variables that satisfy a specific condition, use the scoped variants, impute_below_at, and impute_below_if. To use _at effectively, you must know that _at`` affects variables selected with a character vector, or with vars()`.

Usage

impute_median_all(.tbl)

impute_median_at(.tbl, .vars)

impute_median_if(.tbl, .predicate)

Arguments

.tbl

a data.frame

.vars

variables to impute

.predicate

variables to impute

Value

an dataset with values imputed

Examples

Run this code
# NOT RUN {
# select variables starting with a particular string.
impute_median_all(airquality)

impute_median_at(airquality,
               .vars = c("Ozone", "Solar.R"))
# }
# NOT RUN {
library(dplyr)
impute_median_at(airquality,
                .vars = vars(Ozone))

impute_median_if(airquality,
                .predicate = is.numeric)

library(ggplot2)
airquality %>%
  bind_shadow() %>%
  impute_median_all() %>%
  add_label_shadow() %>%
  ggplot(aes(x = Ozone,
             y = Solar.R,
             colour = any_missing)) +
         geom_point()
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab