glimpse_na: Show the number of (remaining) missing values.

Description Usage Arguments Details Examples

View source: R/utils.R

Description

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.

Usage

1
2
3
glimpse_na(x, show_only_missing = TRUE, ...)

lhs %?>% rhs

Arguments

x

an R object caryying data (e.g. data.frame)

show_only_missing

if TRUE only columns with NA's will be printed.

...

arguments passed to na_status.

lhs

left hand side of pipe

rhs

right hand side of pipe

Details

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
if (requireNamespace("dplyr")){
   library(dplyr)
   
   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)  
}

simputation documentation built on Sept. 16, 2021, 5:11 p.m.