Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2020 03:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ipums_clean_dta <- function(
d = NULL, numeric_convert = NULL, string_as_factors = TRUE, clean_labels = FALSE,
mis_lab = c("unknown", "niu (not in universe)", "not reported/missing",
"unknown/missing", "response suppressed", "unclassifiable")
d %>%
{if(clean_labels) dplyr::mutate_if(is.labelled, ipumsr::lbl_clean) else .} %>%
dplyr::mutate_if(is.labelled, ~ipumsr::lbl_na_if(., ~.lbl %in% mis_lab)) %>%
dplyr::mutate_at({numeric_convert}, haven::zap_labels) %>%
dplyr::mutate_if(is.labelled, haven::as_factor) %>%
{if(!string_as_factors) dplyr::mutate_if(., is.factor, as.character) else .}
# library(devtools)
# source_url("")
# ipums_clean_dta(d0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment