library(Amelia)
library(magrittr)
library(plyr)
library(dplyr)
data(freetrade)
# % missing by variable
n_NA <- plyr::colwise(function(x) { is.na(x) %>% sum() })
(n_NA(freetrade) / nrow(freetrade)) %>% write.csv("freetrade_missing_data_by_variable.csv", row.names = FALSE)
# count (freq) and % of total for each combination of missing data elements
# across all observations
freetrade %>%
is.na() %>%
not() %>%
plyr::count() %>%
dplyr::mutate(percent = freq/sum(freq)) %>%
dplyr::arrange(desc(percent)) %>%
write.csv("freetrade_missing_data_combos.csv", row.names = FALSE)