Skip to content

Instantly share code, notes, and snippets.

@joelgombin
Last active May 6, 2020 16:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelgombin/c3404877787181b96ffa383165a5216a to your computer and use it in GitHub Desktop.
Save joelgombin/c3404877787181b96ffa383165a5216a to your computer and use it in GitHub Desktop.
Compter tous les nulls et autres d'un JDD
library(tidyverse)
base <- read_csv("./Documents/Base_menage-extrait.csv")
is_null_vector <- function(x) purrr::map_lgl(x, ~ is.null(.))
base %>%
summarise(across(.fns = list(NAs = ~ sum(is.na(.)),
NULLs = ~ sum(is_null_vector(.) | . %in% "NULL"),
empties = ~ sum(. %in% "")))) %>%
pivot_longer(everything()) %>%
separate(name, c("name", "type"), "_(?=NAs|NULLs|empties)") %>%
pivot_wider(names_from = type, values_from = value)
@joelgombin
Copy link
Author

# A tibble: 341 x 4
   name                    NAs NULLs empties
   <chr>                 <int> <int>   <int>
 1 id_menage                 0     0       0
 2 code_enregistrement       0     0       0
 3 code_cim                  0     0       0
 4 codeancien              100     0       0
 5 dossier                   0   100       0
 6 id_demandeinscription     0     0       0
 7 id_progpartenaire         0     0       0
 8 date_ajout                0    99       0
 9 codeutilisateurajout      0   100       0
10 id_demandeorigine         0     0       0
# … with 331 more rows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment