I have the following R dataframe (with header):
A B C x y
a1 b1 c1 0.68 0.43
a1 b1 c2 -0.52 0
a1 b2 c1 -0.58 -0.32
a1 b2 c2 -1.36 -0.73
a2 b1 c1 0.68 0.43
a2 b1 c2 -0.52 0
a2 b2 c1 -0.58 -0.32
a2 b2 c2 -1.36 -0.73
and I would like to obtain the following:
C x_a1_b1 y_a1_b1 x_a1_b2 y_a1_b2 x_a2_b1 y_a2_b1 x_a2_b2 y_a2_b2
c1 0.68 0.43 -0.58 -0.32 0.68 0.43 -0.58 -0.32
c2 -0.52 0 -1.36 -0.73 -0.52 0 -1.36 -0.73
I have tried to somehow do it with tidyr::spread()
, but I do not know how I can make it to spread the original table in the desired way.
Any way to make this work?
Thanks!