0

I tried different things. Like the gather function of the tdyr package... but I got no good results...

I have the following table:

year    Sudan   Africa

1964    5.586   13.087
1965    4.885   14.133
1966    4.233   14.343

and I would to have the data like this:

year   country   value

1964   Sudan     5.586
1964   Africa    13.087
1965   Sudan     4.885
1965   Africa    14.133
1966   Sudan     4.233
1966   Africa    14.343

This is only a subset of the data. I have all countries of the world and values from 1964 - 2013.

thx for your help

pampi
  • 37
  • 6

1 Answers1

1

We can use pivot_longer

library(tidyr)
 pivot_longer(df1, cols = -year, names_to = 'country')
akrun
  • 874,273
  • 37
  • 540
  • 662