knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.0     ✔ readr     2.1.6
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.2     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Import your data

data <- tibble(
  country = rep(c("Portugal", "Italy", "Poland"), each = 4),
  year    = rep(2018:2021, times = 3),
  overall_score = round(runif(12, 60, 90), 1)
)

data_small <- data %>%
  filter(country %in% c("Portugal", "Italy", "Poland")) %>%
  filter(year >= 2018)
View(data_small)

Pivoting

Long to wide form

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

Wide to long form

data_long <- data_wide %>%
  pivot_longer(c('2018', '2019', '2020', '2021'), names_to = "year", values_to = "overall_score")

Separating and Uniting

Unite two columns

data_united <- data_small %>%
  unite(col = "overall_score_in_year", overall_score, year, sep = "/")

Separate a column

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

Missing Values