Created
November 2, 2019 01:49
-
-
Save uribo/ccb8ff87287c67fd431d2a71107d0156 to your computer and use it in GitHub Desktop.
tidy estat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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