Hi @Hanz, could you please provide some data in format that is easy to copy/paste - you can see how to do this here: FAQ: What's a reproducible example (reprex
) and how do I do one?
In the meantime, what you might need is the pivot_longer
function from the tidyr
package.
Maybe this example can clarify further:
library(tidyverse)
set.seed(1)
data <- tibble(country = c('A', 'B', 'C'), `2000` = rnorm(3), `2001` = rnorm(3), `2002` = rnorm(3))
pivot_longer(data, cols = -country, names_to = 'Year', values_to = 'some_metric')
#> # A tibble: 9 x 3
#> country Year some_metric
#> <chr> <chr> <dbl>
#> 1 A 2000 -0.626
#> 2 A 2001 1.60
#> 3 A 2002 0.487
#> 4 B 2000 0.184
#> 5 B 2001 0.330
#> 6 B 2002 0.738
#> 7 C 2000 -0.836
#> 8 C 2001 -0.820
#> 9 C 2002 0.576
Created on 2019-12-02 by the reprex package (v0.3.0)