Skip to content

Instantly share code, notes, and snippets.

@uribo
Created November 2, 2019 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uribo/ccb8ff87287c67fd431d2a71107d0156 to your computer and use it in GitHub Desktop.
Save uribo/ccb8ff87287c67fd431d2a71107d0156 to your computer and use it in GitHub Desktop.
tidy estat
read_ks_pop <- function(path, .tidy = TRUE) {
d <-
vroom::vroom(path,
locale = vroom::locale(encoding = "cp932"),
skip = 1,
col_types = paste0(c("cii"),
paste(rep("d", 42), collapse = ""), collapse = ""))
fix_names <-
stringi::stri_trans_nfkc(names(d)) %>%
stringr::str_trim() %>%
stringr::str_replace_all("[[:space:]]", "_")
fix_names[seq_len(4)] <- c("key_code", "htksyory", "htksaki", "gassan")
d <-
d %>%
purrr::set_names(fix_names)
if (.tidy == TRUE) {
d %>%
tidyr::pivot_longer(cols = 5:45, names_to = "key",values_to = "value")
} else {
return(d)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment