Skip to content

Commit

Permalink
a few more uses of colSums(is.na(data) to improve speed
Browse files Browse the repository at this point in the history
  • Loading branch information
njtierney committed May 19, 2020
1 parent 79a12e8 commit af836b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions R/gg-miss-which.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/where-na.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit af836b2

Please sign in to comment.