0

I have a dataset of the following form

AFG 0011 7

ALB 0011 23

NLD 0011 234

USA 0011 245

AFG 0012 5

ALB 0012 12

NLD 0012 345

USA 0012 334

ALB 0013 34

NLD 0013 56

USA 0013 59

NLD 0015 67

USA 0015 68

I need to transform it into the following conventional matrix

AFG  ALB  NLD  USA

0011 7 23 234 245

0012 5 12 345 334

0013 NA 34 56 59

0015 NA NA 67 68

I'm fine if NAs are sustituted with 0s. Unfortunately, I was not able to find a simple solution, as subvectors (AFG, ALB, NLD, USA or NLD, USA) are of different lengths. Will be very grateful for any help.

  • Search for any questions related to reshaping data from long to wide and you should find your answer. – A5C1D2H2I1M1N2O1R2T1 Feb 13 '18 at 12:32
  • Solved by myself, but not in an elegant way, though... – Ivan Lyubimov Feb 13 '18 at 13:34
  • If you have a solution, you can always share that or share where you're stuck. Simply posting input and expected output data isn't the best way to get help here. See, in particular, the [scope of questions part](https://stackoverflow.com/tags/r/info) of [tag:r]. See also https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – A5C1D2H2I1M1N2O1R2T1 Feb 13 '18 at 14:49

0 Answers0