I'm struggling with a sizeable panel data in long format with multiple variables. It looks like this
set.seed(42)
    dat_0=
      data.frame(
      c(rep('AFG',2),rep('UK',2)),
      c(rep(c('GDP','pop'),2)),
      runif(4),
      runif(4))
    colnames(dat_0)<-c('country','variable','2010','2011')
Producing a data frame like this:
  country variable        2010      2011
1     AFG      GDP 0.535761290 0.7515226
2     AFG      pop 0.002272966 0.4527316
3      UK      GDP 0.608937453 0.5357900
4      UK      pop 0.836801559 0.5373767
And I am trying/struggling to coerce it to this structure
    country   year        GDP      pop
1     AFG     2010 0.5357612   0.0022729
2     AFG     2011 0.7515226   0.4527316
3      UK     2010 0.6089374   0.8368015
4      UK     2011 0.5357900   0.5373767
Apologies if repeated, I seem to be struggling with reshape/tidyr/dplyr
 
     
    