Import your data

data <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-11-25/spi_indicators.csv')
## Rows: 4340 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): iso3c, country, region, income
## dbl (8): year, population, overall_score, data_use_score, data_services_scor...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data_small <- data %>%
  
  select(country, year, overall_score) %>%
  filter (country %in% c("Denmark", "Finland", "Poland")) %>%
  filter(year >= 2016)

Pivoting

long to wide form

data_wide <- data_small %>%
  pivot_wider(names_from = year, values_from = overall_score)

# Print the wide tibble
data_wide
## # A tibble: 3 × 9
##   country `2023` `2022` `2021` `2020` `2019` `2018` `2017` `2016`
##   <chr>    <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>
## 1 Denmark   95.3   93.2   94.4   89.5   88.9   88.8   81.1   79.6
## 2 Finland   95.1   93.7   94.3   90.8   88.8   88.7   88.5   87.5
## 3 Poland    94.7   94.2   94.6   89.9   89.1   88.2   82.6   81.7

wide to long form

data_long <- data_wide %>% pivot_longer(('2016':'2023'), names_to = "year", values_to = "overall_score")

# Print the long tibble
data_long
## # A tibble: 24 × 3
##    country year  overall_score
##    <chr>   <chr>         <dbl>
##  1 Denmark 2016           79.6
##  2 Denmark 2017           81.1
##  3 Denmark 2018           88.8
##  4 Denmark 2019           88.9
##  5 Denmark 2020           89.5
##  6 Denmark 2021           94.4
##  7 Denmark 2022           93.2
##  8 Denmark 2023           95.3
##  9 Finland 2016           87.5
## 10 Finland 2017           88.5
## # ℹ 14 more rows

Separating and Uniting

Unite two columns

data %>%
  
  unite(col = "services_vs_overall", data_services_score:overall_score, sep = "/")
## # A tibble: 4,340 × 10
##    iso3c country     region          income  year population services_vs_overall
##    <chr> <chr>       <chr>           <chr>  <dbl>      <dbl> <chr>              
##  1 DNK   Denmark     Europe & Centr… High …  2023    5946952 98.4666666666666/1…
##  2 FIN   Finland     Europe & Centr… High …  2023    5584264 96.4333333333333/1…
##  3 POL   Poland      Europe & Centr… High …  2023   36685849 97.3/100/94.65375  
##  4 SWE   Sweden      Europe & Centr… High …  2023   10536632 96/100/94.41       
##  5 ESP   Spain       Europe & Centr… High …  2023   48373336 91.2/100/94.325    
##  6 NLD   Netherlands Europe & Centr… High …  2023   17879488 96.9/100/94.3225   
##  7 SVN   Slovenia    Europe & Centr… High …  2023    2120937 97.5333333333333/1…
##  8 PRT   Portugal    Europe & Centr… High …  2023   10525347 96.8666666666667/1…
##  9 ITA   Italy       Europe & Centr… High …  2023   58761146 93/100/93.63875    
## 10 NOR   Norway      Europe & Centr… High …  2023    5519594 97.2333333333333/1…
## # ℹ 4,330 more rows
## # ℹ 3 more variables: data_products_score <dbl>, data_sources_score <dbl>,
## #   data_infrastructure_score <dbl>
data_small <- data_small %>%
  mutate(overall_score = round(overall_score, 2))
data_united <- data_small %>%
  
  unite(col = "overall_score_in_year", overall_score, year, sep = "/")

# Display tibble
data_united
## # A tibble: 24 × 2
##    country overall_score_in_year
##    <chr>   <chr>                
##  1 Denmark 95.26/2023           
##  2 Finland 95.12/2023           
##  3 Poland  94.65/2023           
##  4 Poland  94.19/2022           
##  5 Finland 93.75/2022           
##  6 Denmark 93.2/2022            
##  7 Poland  94.59/2021           
##  8 Denmark 94.41/2021           
##  9 Finland 94.31/2021           
## 10 Finland 90.79/2020           
## # ℹ 14 more rows

Separate a column

data_separated <- data_united %>%
  
  separate( col = overall_score_in_year, into = c("overall_score", "year"), sep = "/", convert = TRUE)

# Display tibble
data_separated
## # A tibble: 24 × 3
##    country overall_score  year
##    <chr>           <dbl> <int>
##  1 Denmark          95.3  2023
##  2 Finland          95.1  2023
##  3 Poland           94.6  2023
##  4 Poland           94.2  2022
##  5 Finland          93.8  2022
##  6 Denmark          93.2  2022
##  7 Poland           94.6  2021
##  8 Denmark          94.4  2021
##  9 Finland          94.3  2021
## 10 Finland          90.8  2020
## # ℹ 14 more rows

Missing Values