[R] transposing a data frame from horizontal to vertical (stacking)

Hadley Wickham hadley at rice.edu
Tue Jun 29 19:25:28 CEST 2010


On Tue, Jun 29, 2010 at 12:22 PM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote:
> Hello, everyone!
> I have a very simple task - I have a data frame (see MyData below) and
> I need to stack the data (see result below).
> I wrote the syntax below - it's very basic and it does what I need.
> But I am sure what I am trying to do is a very typical task and there
> must be a much shorter/more elegant way of doing it.
> Any advice?

library(reshape)
melt(MyData)

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list