Created
November 17, 2020 19:54
-
-
Save jtrecenti/f63f2a56a883edd04a1acc495a534c94 to your computer and use it in GitHub Desktop.
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
# leitura dos arquivos | |
f <- "~/Downloads/relatorio.xlsx" | |
skips <- c(9, 10, 10, 10) | |
sheets <- readxl::excel_sheets(f) | |
da_list <- purrr::map2(sheets, skips, ~readxl::read_excel(f, .x, skip = .y)) %>% | |
purrr::map(janitor::clean_names) %>% | |
purrr::set_names(sheets) %>% | |
dplyr::bind_rows(.id = "id") | |
# semente para garantir reprodutibilidade | |
set.seed(20201117) | |
# gerando amostras | |
da_tema1 <- da_list %>% | |
dplyr::filter(stringr::str_detect(id, "lista 1")) %>% | |
dplyr::distinct(numero, .keep_all = TRUE) %>% | |
dplyr::sample_frac(1) %>% | |
dplyr::select(-id) %>% | |
tibble::rowid_to_column("id_amostra") | |
da_tema2 <- da_list %>% | |
dplyr::filter(stringr::str_detect(id, "lista 2")) %>% | |
dplyr::distinct(numero, .keep_all = TRUE) %>% | |
dplyr::sample_frac(1) %>% | |
dplyr::select(-id) %>% | |
tibble::rowid_to_column("id_amostra") | |
writexl::write_xlsx(list( | |
tema1 = da_tema1, | |
tema2 = da_tema2 | |
), path = "~/Downloads/amostras.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment