-
Notifications
You must be signed in to change notification settings - Fork 3
Reservas Internacionales #39
Copy link
Copy link
Open
Description
URL <- "https://cdn.bancentral.gov.do/documents/estadisticas/sector-externo/documents/reservas_internacionales.xlsx"
file <- tempfile(fileext = ".xlsx")
download.file(url = URL, destfile = file, mode = "wb")
xopen::xopen(file)
headers <- readxl::read_excel(
file,
skip = 5,
n_max = 3,
col_names = FALSE,
col_types = "text"
)
years <- headers[1, ] |>
tidyr::pivot_longer(dplyr::everything(), names_to = "colum", values_to = "year") |>
dplyr::select(-colum) |>
tibble::rowid_to_column("column") |>
tidyr::fill(year) |>
dplyr::mutate(year = stringr::str_extract(year, "\\d{4}")) |>
dplyr::slice(-1)
variable <- headers[2, ] |>
dplyr::mutate(dplyr::across(2, \(x) "RESERVAS")) |>
tidyr::pivot_longer(dplyr::everything(), names_to = "colum", values_to = "variable") |>
dplyr::select(-colum) |>
tibble::rowid_to_column("column") |>
tidyr::fill(variable) |>
dplyr::slice(-1)
modalidad <- headers[3, ] |>
tidyr::pivot_longer(dplyr::everything(), names_to = "colum", values_to = "modalidad") |>
dplyr::select(-colum) |>
tibble::rowid_to_column("column") |>
dplyr::slice(-1)
readxl::read_excel(file, skip = 8, n_max = 12, col_names = FALSE) |>
tidyr::pivot_longer(-c(1), names_to = "column", values_to = "value") |>
dplyr::mutate(column = readr::parse_number(stringr::str_extract(column, "\\d+"))) |>
dplyr::rename(mes = 1) |>
dplyr::left_join(years) |>
dplyr::left_join(variable) |>
dplyr::left_join(modalidad) |>
dplyr::mutate(
dplyr::across(c(variable, modalidad), stringr::str_to_title),
mes = databcrd::crear_mes(mes),
date = lubridate::make_date(year, mes, 1)
) Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels