View source: R/tidy_ifdata_reports.R
| tidy_ifdata_reports | R Documentation |
Transforms raw ifdata reports downloaded with get_ifdata_reports() into a clean, wide-format dataset suitable for
analysis. This function handles data input from multiple sources (direct
data.frame), removes unnecessary columns, renames
identifiers, and pivots the data from long to wide format.
tidy_ifdata_reports(data)
data |
Optional. A data.frame/tibble.
The data must be downloaded via |
The function performs the following operations in sequence:
Data Input Handling: Accepts data in two forms:
Direct tibble/data.frame (preferred for in-memory operations)
Column Removal: Drops metadata columns that are redundant after pivoting (grupo, conta, numero_relatorio, etc.)
Identifier Rename: Renames cod_inst to cnpj for clarity
that rows represent financial institutions by their CNPJ identifier
Pivot Operation: Transforms from long format (each report metric in
a separate row) to wide format (each metric becomes a column). The pivot
uses nome_coluna for column names and saldo for cell values.
Name Cleaning: Applies janitor's name standardization to ensure consistent, R-friendly column naming
A tibble with the following transformations applied:
Columns removed: grupo, conta, numero_relatorio, nome_relatorio, tipo_instituicao, descricao_coluna
Column renamed: cod_inst → cnpj
Structure pivoted: Long format (multiple rows per institution) → Wide format (one row per institution with columns for each report item)
Column names: Cleaned to lowercase with underscores via
clean_names
get_ifdata_reports for downloading raw data
# Tidy an existing data.frame
raw_data <- get_ifdata_reports(year = 2024, month = 12,
type_institution = 2, report = 4)
tidy_data <- tidy_ifdata_reports(data = raw_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.