This question already has an answer here:
I have a very simple data frame called PlantGrowth that I am trying to change from long format to wide. The data frame has two columns one's name is group and the other weight. The data frame looks like this.
there are 30 observations 10 for each group. The three groups are ctrl, trt1, trt2. I want to have the data frame in wide format with each group as a column and with 10 rows of its entries from the weight column. I have used the melt function as so
melt(PlantGrowth, id=c("group"))
it produces a complete different result than desired
I have been trying other functions like spread and reshape but im getting some kind of error. I dont know what the trick is to get it to work.