df1
Reg Source Year Values
A From1 2003 7512
B From1 2000 7830
C From1 2000 7830
C From2 2001 7830
D From1 2002 1734
D From2 2003 1734
I have a dataframe (df1) that I group_by Reg, Source and Year, then transpose the columns Year into rows names, and Values into rows, but I keep Reg and Source as columns. Expected result is:
Output
Reg Source 2000 2001 2002 2003
A From1 0 0 0 7512
B From1 7830 0 0 0
C From1 7830 0 0 0
C From2 0 7830 0 0
D From1 0 0 1734 0
D From2 0 0 0 1734
I might have duplicates values so when I group_by(Reg, Source, Year) then spread() it returns an error
Each row of output must be identified by a unique combination of keys