1
#' Summary of missing values
2
#'
3
#' @param .data Data frame.
4
#' @param dependent Optional character vector: name(s) of depdendent
5
#'   variable(s).
6
#' @param explanatory Optional character vector: name(s) of explanatory
7
#'   variable(s).
8
#' @param digits Number of decmial places to show for percentage missing.
9
#'
10
#' @return Data frame.
11
#' @export
12
#' 
13
#' @importFrom pillar new_pillar_type
14
#'
15
#' @examples
16
#' colon_s %>%
17
#' 	missing_glimpse()
18
missing_glimpse <- function(.data, dependent=NULL, explanatory=NULL, digits = 1){
19 1
	if(is.null(dependent) && is.null(explanatory)){
20 1
		df.in = .data
21
	}else{
22 1
		keep = names(.data) %in% c(dependent, explanatory)
23 1
		df.in = .data[keep]
24
	}
25

26 1
	df.in %>%
27 1
		purrr::map_df(function(x){
28 1
			var_type = pillar::new_pillar_type(x) %>% paste0("<", ., ">")
29 1
			obs = length(x)
30 1
			missing_n = sum(is.na(x))
31 1
			n = obs-missing_n
32 1
			missing_percent = round_tidy(100*missing_n/obs, digits=digits)
33 1
			tibble::tibble(var_type, n, missing_n, missing_percent)
34 1
		}) -> df.out1
35

36 1
	df.in %>%
37 1
		extract_variable_label() %>%
38 1
		data.frame(label=.) -> df.out2
39

40 1
	df.out = data.frame(df.out2, df.out1)
41 1
	return(df.out)
42
}

Read our documentation on viewing source code .

Loading