I have the following example dataframe that I need to reshape but am not able to use the reshape or cast functions to do what I need to
df
Testee Gender UniqueIdentifier BirthYear Graph V1 V2 V3 V4
1 7685906 1 33448683-29373 1996 1 4 6 6 5
2 NA NA NA 2 7 2 9 6
3 NA NA NA 3 -3 4 -3 -1
4 7685910 2 33444446-47897 1997 1 8 0 3 4
5 NA NA NA 2 7 9 3 2
6 NA NA NA 3 1 -9 0 2
I want to transpose the row values for V1, V2, V3, and V4 for each Graph (1, 2 and 3). So I need 12 columns: Graph1.V1 Graph1.V2 Graph1.V3 Graph1.V4 Graph2.V1 Graph2.V2 etc but I'm struggling with the cast function
This is the desired output
df2
Testee Gender UniqueIdentifier BirthYear X1.V1 X1.V2 X1.V3 X1.V4 X2.V1 X2.V2 X2.V3 X2.V4 X3.V1 X3.V2 X3.V3 X3.V4
1 7685906 1 33448683-29373 1996 4 6 6 5 7 2 9 6 -3 4 -3 -1
2 7685910 2 33444446-47897 1997 8 0 3 4 7 9 3 2 1 -9 0 2
Any help is appreciated!