How can I get from the data.frame below in R to the other data.frame. I am new to dplyr/tidyr, so do not know exactly what functions to use, but I guess it can be done using these packages.
NAME GROUP X1 X2
A G1 1 2
A G2 1 3
A G3 4 3
B G1 3 3
B G2 2 3
B G3 5 4
C G1 4 3
C G2 4 1
C G3 4 3
NAME X1_G1 X2_G1 X1_G2 X2_G2 X1_G3 X2_G3
A 1 2 1 3 4 3
B 4 3 3 3 2 3
C 4 3 4 1 4 3
Thank you for your help!