从csv重新排列R中的数据帧

时间:2016-04-28 11:52:52

标签: r dataframe format

我想以精巧的方式重新排列数据框。通过使用as.data.frame(),我已经尝试了很多次但仍然无法得到我想要的东西。这是我从csv中读到的。

                 score1990   score1990  score1990 score1986  score1986 score1986
Country    Year  Both        Female     Male      Both       Female    Male 
Afghanistan 2013    61  62  61  16  17  15  
Afghanistan 2012    60  61  58  16  17  15  
Albania 2013    74  76  73  19  20  18  
Albania 2012    74  75  73  19  20  18  
Albania 2000    70  73  68  17  18  15

这就是我想要获得的

Country    Year  Sex    score1990   score1986
Afghanistan 2013 Both   61        16        
Afghanistan 2013 Female 62        17    
Afghanistan 2013 Male   61        15    
   : 
   :
Albania 2012    Both    74        19    
Albania 2012    Female  75        20

0 个答案:

没有答案