There is a dataframe, example
df<-data.frame("x"=c(10,15,20,25),
"y1"=c(0,1,0,1),
"y2"=c(1,1,1,0))
I am trying to restructure it vertically to the form
df1<-data.frame("x"=c(10,10,15,15,20,20,25,25),
"y"=c(0,1,1,1,0,1,1,0))
so that the columns y1 and y2 changes to a single column y.
I tried using the reshape package and the melt function, as follows
library(reshape)
df1 <- melt(df, y=c("x","y1","y2"))
But it fails to work and reports the following error message:
Using as id variables
I have also followed similar problems (e.g. How do I flip rows and columns in R) but these do not fit into the specifics of my problem. Any help on this is well appreciated.