Quick indication of the amount and location of missing values.
The function uses na_status
to print the missing values, but
returns the original x
(invisibly) and therefore can be used in an imputation pipeline
to peek at the NA's status.
glimpse_na(x, show_only_missing = TRUE, ...)lhs %?>% rhs
an R object caryying data (e.g. data.frame
)
if TRUE
only columns with NA
's will be
printed.
arguments passed to na_status
.
left hand side of pipe
right hand side of pipe
glimpse_na
is especially helpful when interactively adding imputation methods.
glimpse_na
is named after glimpse
in dplyr
.
Operator %?>%
is syntactic sugar: it inserts a glimpse_na
in
the pipe.
irisNA <- iris
irisNA[1:3,1] <- irisNA[3:7,2] <- NA
# How many NA's?
na_status(irisNA)
# add an imputation method one at a time
iris_imputed <-
irisNA |>
glimpse_na() # same as above
# ok, glimpse_na says "Sepal.Width" has NA's
# fix that:
iris_imputed <-
irisNA |>
impute_const(Sepal.Width ~ 7) |>
glimpse_na() # end NA
# Sepal.Length is having NA's
iris_imputed <-
irisNA |>
impute_const(Sepal.Width ~ 7) |>
impute_cart(Sepal.Length ~ .) |>
glimpse_na() # end NA
# in an existing imputation pipeline we can peek with
# glimpse_na or %?>%
iris_imputed <-
irisNA |>
glimpse_na() |> # shows the begin NA
impute_const(Sepal.Width ~ 7) |>
glimpse_na() |> # after 1 imputation
impute_cart(Sepal.Length ~ .) |>
glimpse_na() # end NA
# or
iris_imputed <-
irisNA %?>%
impute_const(Sepal.Width ~ 7) %?>%
impute_cart(Sepal.Length ~ .)
na_status(iris_imputed)
Run the code above in your browser using DataLab