
Pivot Data360 dataset to wide format
pivot_data360.RdThis function reshapes a Data360-style dataset from long to wide format.
It spreads indicator values (OBS_VALUE) across multiple columns based on
the indicator variable (INDICATOR), while keeping the reference area and
time period identifiers. The resulting dataset is renamed and cleaned to
have snake_case variable names.
Value
A tibble in wide format with columns:
country_code: The country or region code (fromREF_AREA)year: The year or time period (fromTIME_PERIOD)One column per unique
INDICATOR, containing corresponding values fromOBS_VALUE
Details
This function is particularly useful for preparing Data360 or similar
datasets for analysis, where multiple indicators are recorded by country
and year. The output dataset is cleaned using janitor::clean_names() to
ensure consistent naming.
Examples
library(dplyr)
library(tidyr)
data_long <- tibble(
REF_AREA = c("USA", "USA", "CAN", "CAN"),
TIME_PERIOD = c(2020, 2020, 2020, 2020),
INDICATOR = c("GDP", "POP", "GDP", "POP"),
OBS_VALUE = c(21000, 330, 1800, 38)
)
data_wide <- pivot_data360(data_long)
print(data_wide)
#> # A tibble: 2 × 4
#> country_code year gdp pop
#> <chr> <dbl> <dbl> <dbl>
#> 1 USA 2020 21000 330
#> 2 CAN 2020 1800 38