I would like to transform two columns of data of my data frame to a wider format using two category columns, I found similar topics that used the reshape or melt functions, but was still not able to figure it out how it works when you have two id columns. I have the following data frame:
Testphase <- c("BG15_H_D_X","BG15_H_D_X","BG15_H_D_X","BG15_H_D_X","BG15_H_D_Y","BG15_H_D_Y","BG15_H_D_Y","BG15_H_D_Y")
RPM <- c("100","100","200","200","100","100","200","200")
Angle <- c("15","30","15","30","15","30","15","30")
Data1 <- c(1.17,0.65,0.56,0.49,1.14,0.86,0.53,0.72)
Data2 <- c(0.41,0.57,0.56,0.45,0.46,0.4,0.73,0.51)
df <- data.frame(Testphase, RPM, Angle, Data1, Data2)
And I would like to transfer it to:
RPM <- c("100","100","200","200")
Angle <- c("15","30","15","30")
Data1.X <- c(1.17,0.65,0.56,0.49)
Data1.Y <- c(1.14,0.86,0.53,0.72)
Data2.X <- c(0.41,0.57,0.56,0.45)
Data2.Y <- c(0.46,0.4,0.73,0.51)
df_wide <-data.frame(RPM, Angle, Data1.X, Data1.Y, Data2.X, Data2.Y)
BONUS: just use the last letter of testphase to give name to the new created columns, so Data1.X instead of Data1.BG15_H_D_X.