My data.frame
a<-sample(12)
b<-sample(-100:100, 12)
d<-c(-11:0)
O<-rep(c("N","H"), each=6)
H<-rep(c("In+", "In-"), each=3, times=2)
ID<-rep(c("bo","co", "do", "fo"), each=3)
mydata_1<-data.frame(ID, a, b, d, O, H)
I want to melt the dataframe variables a, b, d; while O and H should be ordered like the ID. My solution below:
mydata_2<-data.frame(ID, a, b, d)
gg.df <- melt(mydata, id="ID", variable.name="int")
O<-rep(c("N","H"), each=6, times=3)
H<-rep(rep(c("In+", "In-"), each=3, times=2), times=3)
gg.df[, "OX"] <- O
gg.df["HI"] <- H
I am wondering how this can be done inside the melt function by using the full dataframe (mydata_1)