Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205491

Using melt in R to change DF from long to wide [duplicate]

$
0
0

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.

enter image description here

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.


Viewing all articles
Browse latest Browse all 205491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>