0
ID         Period       Grade
1          P1           2    
1          P2           3     
1          P3           3     
1          P4           2

Output Required

Id         P1         P2       P3      P4    
1          2          3        3       2   

I'm trying this in R, basically we need to show grade in each period for the client 1,2 and so on.

pogibas
  • 27,303
  • 19
  • 84
  • 117
VA25
  • 1
  • 3

1 Answers1

0

Use data.table package to transform data long to wide format.

library(data.table)
dcast(INPUT, ID ~ Period, value.var = "Grade")

ID P1 P2 P3 P4
1  2  3  3  2
pogibas
  • 27,303
  • 19
  • 84
  • 117
  • I've one more question related to this. What we can do if we want assign particular format to pivot. I'm trying to calculate migration of rating from year 2014 to 2015 and then 2015 to 2016 but I need a fixed format. There might be chance that rating appeared in year 2014 will not appear in 2015. for example – VA25 Sep 24 '17 at 07:18