From af836b269db69f1bb1032beb22c3a8824835c6b1 Mon Sep 17 00:00:00 2001 From: Nicholas Tierney Date: Tue, 19 May 2020 18:25:34 +1000 Subject: [PATCH] a few more uses of colSums(is.na(data) to improve speed --- R/gg-miss-which.R | 11 ++++++----- R/where-na.R | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/R/gg-miss-which.R b/R/gg-miss-which.R index c9f154da..649fb41f 100644 --- a/R/gg-miss-which.R +++ b/R/gg-miss-which.R @@ -21,12 +21,13 @@ gg_miss_which <- function(x){ + col_na <- colSums(is.na(x)) == 0 + col_na_val <- dplyr::if_else(col_na, "complete", "missing") + + # tell us which columns have missing data - ggobject <- x %>% - miss_var_summary() %>% - dplyr::select(variable, - value = n_miss) %>% - dplyr::mutate(value = dplyr::if_else(value == 0, "complete", "missing")) %>% + ggobject <- tibble::tibble(variable = names(col_na), + value = col_na_val) %>% dplyr::mutate(nheight = 1) %>% ggplot(data = ., aes(x = variable, diff --git a/R/where-na.R b/R/where-na.R index 36077dde..97bb5e69 100644 --- a/R/where-na.R +++ b/R/where-na.R @@ -79,7 +79,7 @@ miss_var_which <- function(data){ } # else return variables that contain ANY missing values - na_vars <- names(which(purrr::map_lgl(data,anyNA) == TRUE)) + na_vars <- names(which(colSums(is.na(data)) > 0)) return(na_vars)